简体   繁体   English

无法使用PHP在SQLite3中添加行,未显示错误消息

[英]Can't add rows in SQLite3 with PHP, no error message displayed

I'm using PHP 5.3.19 and SQLite3 and I can't seem to add any rows to my table using PHP, and I don't get any error messages either. 我正在使用PHP 5.3.19和SQLite3,但似乎无法使用PHP向我的表添加任何行,而且我也没有收到任何错误消息。 I do manage to do a select, but the INSERTS are not working. 我确实做了一个选择,但是插入无法正常工作。

code: 码:

try  {  
  $dbh = new PDO("sqlite:database.db");
  $dbh->exec("INSERT INTO TABLE_NAME (COL1, COL2, COL3) VALUES (null, $var1, $var2)");      
  echo "Row added";
}
catch(PDOException $e) {
  echo $e->getMessage();
  echo "<br><br>Database <b>NOT</b> loaded successfully. ";
  die( "<br><br>Query Closed! $error");
}   

this executes without any error messages, but the entry is not saved. 这将执行而没有任何错误消息,但不会保存该条目。

The directory is owned by webservd and is writable by webservd, so I really don't know what the problem is. 该目录归webservd所有,可被webservd写入,因此我真的不知道问题出在哪里。 When I run a PHP script via CLI, it doesn't do anything either, But if I try to enter the rows manually, it does work. 当我通过CLI运行PHP脚本时,它也不执行任何操作,但是,如果我尝试手动输入行,则可以正常工作。

I checked the other posts about PHP and SQLite3, especially Unable to write to a chmod 777 database file on SQlite3 via php 5.3.0 , but couldn't find an answer. 我检查了有关PHP和SQLite3的其他帖子,尤其是无法通过php 5.3.0写入SQlite3上的chmod 777数据库文件 ,但找不到答案。

Am I missing anything? 我有什么想念的吗?

Thanks in advance for your help 在此先感谢您的帮助

I think you missed something; 我想你错过了什么; If your col2 and col3 is a string it should look something like: 如果您的col2和col3是一个字符串,它应该类似于:

$dbh->exec("INSERT INTO TABLE_NAME (COL1, COL2, COL3) VALUES (null, '$var1', '$var2')");

Don't ye forget that yer directory as well as yer database be needin' write permissions, beist ye usin sqlite in Unix or Linux. 别忘了您的目录以及您的数据库都需要具有写权限,因为您在Unix或Linux中使用sqlite。 Arrrr... 啊...

After the query [example: $query = $db->query("INSERT INTO table (column1, column2...) VALUES ('$value1','$value2'...)" )] add the clause "OR DIE" with the function last error code of sqlite3 [example: $db-> LastErrorCode()); 查询后[示例: $query = $db->query("INSERT INTO table (column1, column2...) VALUES ('$value1','$value2'...)" )]添加子句“ OR DIE”,其功能为sqlite3的最后错误代码[示例: $db-> LastErrorCode()); ]. ]。 This way you get the error code if it exists. 这样,您将获得错误代码(如果存在)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM