Getting parse errors when building insert queries in PDO
new to PDO (version php-pdo-5.3.5-1.el5) and running into the following error when trying to use PDO for a MySQL insert:
PHP Parse error: syntax error, unexpected ';' in /var/www/appdb/test.php on line 3
Here is the code I am using:
<?php
$DBH = new PDO("mysql:host=localhost;dbname=appdb", sqladmin, password);
$STH = $DBH->prepare("INSERT INTO appdb ( id ) values ( default )");
$STH->execute();
?>
I have been on goog开发者_开发百科le for an hour trying to figure this out and have not been able to determine what could be causing this error. Thanks in advance.
$DBH = new PDO("mysql:host=localhost;dbname=appdb", sqladmin, password);
should probably be
$DBH = new PDO("mysql:host=localhost;dbname=appdb", $sqladmin, $password);
unless you have somewhere define('sqladmin','something');
and define('password','something');
My best guess would be an unterminated string, most probably around the credential arguments to the PDO constructor that you've edited for your question.
I'm guessing you have something like this
$DBH = new PDO("mysql:host=localhost;dbname=appdb", "username", "password);
or similar (note the missing quote at the end).
If you use an editor with syntax highlighting (Notepad++ comes to mind), these errors will quickly become apparent.
精彩评论