PHP PDO语法错误

时间:2013-12-05 06:15:02

标签: php postgresql pdo

请问这个代码有什么问题?

$host = "localhost";
$database = "dbname";
$username = "postgres";
$password = "password";

$inf = "information_schema";
$db = new PDO("pgsql:dbname={$database};host={$host};port=5432", $username, $password);
!$db && exit("Database connect failed");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$handle = fopen("code.txt", "r");
if ($handle) {
    $array = array();
    while (($line = fgets($handle)) !== false) {
        preg_match("/(.*?)\s\((.*?)\)/i", $line, $match);
        $query = "INSERT INTO combo (group,html,value) VALUES(?,?,?)";
        $s = $db->prepare($query);
        $s->bindParam(1, $group);
        $s->bindParam(2, $html);
        $s->bindParam(3, $value);
        $group = "state";
        $html = $match[1];
        $value = $match[2];
        $s->execute();
    }
    var_dump($array);
}

我收到此错误。我也尝试过param名称,例如:html,:value但这不起作用并给出相同的错误。

pelase告诉你这个问题是什么

enter image description here

1 个答案:

答案 0 :(得分:2)

GROUP

是保留字 请看这里http://www.postgresql.org/docs/8.1/static/sql-keywords-appendix.html 你可以使用

`group`