Welcome Guest, Not a member yet? Register   Sign In
SQL query - strange behaviour?
#1

[eluser]Las3r[/eluser]
Hey there,

For my "support ticket overview" page i'm trying to fetch all info from the database, i do this with the following code:

Code:
$db1 = $this->load->database('web', TRUE);
                
        $query = 'SELECT category,ticket_contents FROM
                support_tickets
                WHERE
                sender = ?';
                
        
        $db1->query($query,'las3r');

This gives the following error :

Quote:A Database Error Occurred

Error Number:

SELECT category,ticket_contents FROM support_tickets WHERE sender = 'las3r'

When I execute this query in MSSQL Enterprise studio it shows all the info it should, and the query executes as expected.

HOWEVER (this is the odd part)

when i execute THIS:

Code:
$query = 'SELECT category FROM
                support_tickets
                WHERE
                sender = ?';

It works and gives me a blank screen (no errors). So when i go and fetch 1 item it works, but when i fetch multiple it fails. Normally I'd just use a select * from xxx where yyy, statement, but i keep having problems with CI.

Can anyone help me out ?

The idea is to fetch all the ticket data into an array (happens in Model), then pass the array on to the Controller, to show it in a readable format in the View, but i'm stuck here.

Thank you.

p.s. I have tried to find a solution on the wiki's and the user guide, but they don't really explain this problem I'm experiencing Smile

With some help from pistolPete, i wrote the following function, which works fine:

Code:
function submit_ticket($category,$title,$content)
    {
        $db1 = $this->load->database('web', TRUE);
                
        $sql = 'INSERT INTO support_tickets
                (sender,category,ticket_title,ticket_contents,date,last_edit,is_answered)
                VALUES
                (?,?,?,?, GETDATE() , GETDATE() ,?) ';

        $submit = $db1->query($sql,array($_SESSION['username'],$category,$title,$content,0));
        if ($db1->affected_rows()  == 1)
        {
        return TRUE;
        }
        else
        {
        return FALSE;
        }

In other words, i do know how to write queries and how to extract stuff...


Messages In This Thread
SQL query - strange behaviour? - by El Forum - 03-02-2009, 02:01 PM
SQL query - strange behaviour? - by El Forum - 03-02-2009, 02:11 PM
SQL query - strange behaviour? - by El Forum - 03-02-2009, 02:17 PM
SQL query - strange behaviour? - by El Forum - 03-02-2009, 02:42 PM
SQL query - strange behaviour? - by El Forum - 03-02-2009, 03:08 PM
SQL query - strange behaviour? - by El Forum - 03-02-2009, 03:26 PM
SQL query - strange behaviour? - by El Forum - 03-02-2009, 04:10 PM
SQL query - strange behaviour? - by El Forum - 03-02-2009, 04:14 PM
SQL query - strange behaviour? - by El Forum - 03-02-2009, 04:21 PM
SQL query - strange behaviour? - by El Forum - 03-02-2009, 04:24 PM
SQL query - strange behaviour? - by El Forum - 03-02-2009, 04:28 PM
SQL query - strange behaviour? - by El Forum - 03-02-2009, 04:33 PM
SQL query - strange behaviour? - by El Forum - 03-02-2009, 04:40 PM
SQL query - strange behaviour? - by El Forum - 03-02-2009, 05:02 PM
SQL query - strange behaviour? - by El Forum - 03-02-2009, 05:08 PM
SQL query - strange behaviour? - by El Forum - 03-02-2009, 06:10 PM



Theme © iAndrew 2016 - Forum software by © MyBB