Page 1 of 1

Problem executing a prepared statement with mySQL

Posted: Thu Mar 05, 2009 1:05 pm
by omb10
Hello all,
I have a problem with prepared statements with PDO and Mysql:
when i do the following:

Code: Select all

 
$count = $db->exec("INSERT INTO Customer VALUES ('".$userName ."','". $password .
             "','". $shippingAdd ."','". $billingAdd . "','". $rating ."','". $email ."')");
        $db->commit();
 
The data in correctly inserted in the DB. but when i use prepared statement as follow:

Code: Select all

 
$sth = $db->prepare ("INSERT INTO CUSTOMER(username, password, Shipping_Address, Billing_Address, rating, email_Address) VALUES (:uname, :password, :shipAddress, :billAddress, :rating, :email)");
        $sth->bindValue(':uname:', $userName);
        $sth->bindValue(':password', $password);
        $sth->bindValue(':shipAddress', $shippingAdd);
        $sth->bindValue(':billAddress', $billingAdd);
        $sth->bindValue(':rating', $rating);
        $sth->bindValue(':email', $email);
        $sth->execute();
                $db->commit();
 
The data is not inserted.

am i doing something wrong in my code?

Re: Problem executing a prepared statement with mySQL

Posted: Thu Mar 05, 2009 10:12 pm
by Benjamin
Have you viewed the actual query or tested for errors? Do you have error reporting turned on?

Re: Problem executing a prepared statement with mySQL

Posted: Fri Mar 06, 2009 6:26 am
by omb10
astions wrote:Have you viewed the actual query or tested for errors? Do you have error reporting turned on?
for some reasons when i use ? instead of names it work fine.

Thanks for your help.