Page 1 of 1

PEAR executeMultiple() returned Unknown Error

Posted: Fri Sep 23, 2005 6:02 am
by obasan
Hello there!

The code below returned an unknown error
DB Error: unknown error
What could be wrong? Help appreciated.

Code: Select all

/* print_r ($data); would return

Array
(
    [0] => Array
        (
            [cserial] => 123456789015
            [ccolor] => orange
            [ctaste] => good
        )

    [1] => Array
        (
            [cserial] => 123456789014
            [ccolor] => orange
            [ctaste] => bad
        )

    [2] => Array
        (
            [cserial] => 123456789013
            [ccolor] => white
            [ctaste] => good
        )
)
*/

function add_cookies($data, $type) {

    // DB conn here

    $query = $db->prepare( "INSERT INTO cookies ( 
                            cookie_type, cookie_serial, cookie_color, 
                            cookie_taste 
                            ) VALUES (
                            '$type', ?, ?, ?)");

    $result = $db->executeMultiple($query, $data);

}

add_cookies("danone", $data);

Posted: Fri Sep 23, 2005 6:07 am
by shiznatix
you seriously putting a ? straight into the db like that? that is probably where the error comes from i bet

Posted: Fri Sep 23, 2005 6:08 am
by obasan
The ? will be parsed by PEAR as a variable, which is fetched from $data and applied to corresponding ? during executeMultiple.

Posted: Fri Sep 23, 2005 6:10 am
by obasan
Wait.. do you mean I must enclose it with quotes? Like this --> '?'

I tried that, didn't work :(

Posted: Fri Sep 23, 2005 6:21 am
by shiznatix
ok well maybe im wrong but instead of putting in question marks just try to put in somthing like the letter a or somthing. remember to put it in those quotes too :wink:

Posted: Fri Sep 23, 2005 7:02 am
by obasan
Well obviously if you insert directly a value (instead of putting a ?) everything works just fine. But its a prepare() statement, hence ? is used to be replaced with arrays of data.

God damn Unknown Error.

Anybody could help ?

Posted: Fri Sep 23, 2005 8:10 am
by feyd
start with a single level array.. it's possible it doesn't like that they are associative.. with a single element in the array passed to the function you can fairly easily do a dbms error call to see what the error actually was...

Posted: Fri Sep 23, 2005 11:37 am
by obasan
You're right feyd, I should've done it slowly but surely. Will get back with the results sooner :)

Thanks!