PEAR executeMultiple() returned Unknown Error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
obasan
Forum Newbie
Posts: 5
Joined: Fri Sep 23, 2005 5:58 am

PEAR executeMultiple() returned Unknown Error

Post 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);
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

you seriously putting a ? straight into the db like that? that is probably where the error comes from i bet
obasan
Forum Newbie
Posts: 5
Joined: Fri Sep 23, 2005 5:58 am

Post by obasan »

The ? will be parsed by PEAR as a variable, which is fetched from $data and applied to corresponding ? during executeMultiple.
obasan
Forum Newbie
Posts: 5
Joined: Fri Sep 23, 2005 5:58 am

Post by obasan »

Wait.. do you mean I must enclose it with quotes? Like this --> '?'

I tried that, didn't work :(
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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:
obasan
Forum Newbie
Posts: 5
Joined: Fri Sep 23, 2005 5:58 am

Post 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 ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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...
obasan
Forum Newbie
Posts: 5
Joined: Fri Sep 23, 2005 5:58 am

Post by obasan »

You're right feyd, I should've done it slowly but surely. Will get back with the results sooner :)

Thanks!
Post Reply