mysql, pdo- Syntax error or access violation: 1064
Posted: Mon Sep 05, 2011 3:51 pm
Hi everyone,
I'm having some trouble with a PDO update statement. I'm getting the following:
Here is my code:
Here's my mysql DB
[text]
CREATE TABLE `table1` (
`id` mediumint(9) NOT NULL AUTO_INCREMENT,
`Key` varchar(512) NOT NULL,
`U` varchar(512) NOT NULL,
`ExactMatch` varchar(512) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=48 DEFAULT CHARSET=latin1
[/text]
Any thoughts?
Thank you,
KC
I'm having some trouble with a PDO update statement. I'm getting the following:
Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''key' SET ExactMatch='xxxxx' where Keyword='xxxxxx'' at line 1 in C:\wamp\www\....\exactMatch.php on line 142
Here is my code:
Code: Select all
try {
$table='table1';
$dbh = new PDO("mysql:host=$host;dbname=$db", $user, $pass);
# set the PDO error mode to EXCEPTION, WARNING, or SILENT
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$sql="UPDATE :table SET ExactMatch=:ExactMatch where Key=:key" ;
echo "sql " .$sql.'<br>';
$sth = $dbh->prepare ($sql);
$sth->bindValue (":table",$table );
foreach ($output as $key => $value) {
$sth->bindValue (":ExactMatch",$value );
$sth->bindValue (":key",$key );
$sth->execute ();
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
$dbh = null;
Here's my mysql DB
[text]
CREATE TABLE `table1` (
`id` mediumint(9) NOT NULL AUTO_INCREMENT,
`Key` varchar(512) NOT NULL,
`U` varchar(512) NOT NULL,
`ExactMatch` varchar(512) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=48 DEFAULT CHARSET=latin1
[/text]
Any thoughts?
Thank you,
KC