从PHP插入SQLite3的问题

时间:2011-06-10 09:01:10

标签: php sqlite

我在PHP页面上有奇怪的问题,我试图向表用户(SQLite3)插入新行

 $id=$db->insert_user("'".$parameters['first_name']."'", "'".$parameters['last_name']."'", "'".$parameters['email']."'", "'".$parameters['username']."'", "'".$parameters['password']."'", "'".$parameters['privilege']."'");

其中

     try {
            $db = new SQLite3($this->db_path);

           echo "INSERT INTO users(first_name,last_name,email,username,password,privilege) VALUES('$first_name','$last_name','$email','$username','$password','$privilege');";
           $db->query("INSERT INTO users(first_name,last_name,email,username,password,privilege) VALUES('$first_name','$last_name','$email','$username','$password','$privilege');");

            $last_id = $db->lastInsertRowID();
            echo ''.$last_id;
            $db->close();
            return $last_id;
        } catch (Exception $e) {
            echo 'Exception caught: ', $e->getMessage(), "\n";
        }

INSERT INTO users(first_name,last_name,email,username,password,privilege) VALUES(''drkosh'',''drkosh'',''drkosh'',''drkosh'',''drkosh'',''ignore'');
来自echo的

结果是

INSERT INTO users(first_name,last_name,email,username,password,privilege) VALUES(''drkosh'',''drkosh'',''drkosh'',''drkosh'',''drkosh'',''ignore'');

错误信息很奇怪,它在第35行说,但35在开关中,我从未通过35,有休息。有人有一些线索有什么不对吗? (所有列都可以,表格名称)

1 个答案:

答案 0 :(得分:0)

查看sql查询,有''drkosh'',但应该只有'drkosh'

INSERT INTO users(first_name,last_name,email,username,password,privilege) VALUES(''drkosh'',''drkosh'',''drkosh'',''drkosh'',''drkosh'',''ignore'');

试试这个:

$id=$db->insert_user($parameters['first_name'], $parameters['last_name'], $parameters['email'], $parameters['username'], $parameters['password'], $parameters['privilege']);