Problem executing a prepared statement with mySQL

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
omb10
Forum Newbie
Posts: 3
Joined: Sun Feb 01, 2009 7:09 am

Problem executing a prepared statement with mySQL

Post 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?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Problem executing a prepared statement with mySQL

Post by Benjamin »

Have you viewed the actual query or tested for errors? Do you have error reporting turned on?
omb10
Forum Newbie
Posts: 3
Joined: Sun Feb 01, 2009 7:09 am

Re: Problem executing a prepared statement with mySQL

Post 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.
Post Reply