Rob*_*inJ 2 php sql sqlite pdo
我一直收到此错误消息.它所讨论的数据类型是TEXT,要插入的数据是TEXT,所以我看不出可能出现什么问题.
robin@robin-Latitude-D620:/media/Data/Documenten/PHP/µBot$ php index.php
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626/sqlite.so' - /usr/lib/php5/20090626/sqlite.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 20 datatype mismatch' in /media/Data/Documenten/PHP/µBot/index.php:100
Stack trace:
#0 /media/Data/Documenten/PHP/µBot/index.php(100): PDOStatement->execute()
#1 /media/Data/Documenten/PHP/µBot/index.php(73): addToLog('439', '*', 'irc.gmake.org', ':Please wait wh...')
#2 {main}
thrown in /media/Data/Documenten/PHP/µBot/index.php on line 100
Run Code Online (Sandbox Code Playgroud)
问题所在的代码块(第100行是该块的最后一行):
function addToLog($type, $channel, $host, $message)
{
global $database;
$temp = explode('!', $host);
$nick = $temp[0];
unset($temp);
$timestamp = time();
$nickprefix = '';
$query = $database->prepare("INSERT INTO log VALUES ('', :channel, :nick, :host, :message, :type, :time, '');");
$query->bindParam(':channel', $channel);
$query->bindParam(':nick', $nick);
$query->bindParam(':host', $host);
$query->bindParam(':message', $message);
$query->bindParam(':type', $type);
$query->bindParam(':time', $timestamp);
$query->execute();
}
Run Code Online (Sandbox Code Playgroud)
完整代码:http://pastebin.com/CXCQjqb0
-
SQLite版本:sqlite 2.8.17-6.1ubuntu1
PHP版本:php5-common 5.3.6-13ubuntu3.2
我不知道你的架构,但我猜这id是一个自动增量列,这个:
INSERT INTO log (id, channel, nick, host, message, type timestamp, nickprefix)
VALUES ('', :channel, :nick, :host, :message, :type, :time, '');
Run Code Online (Sandbox Code Playgroud)
正试图在空中插入一个空字符串id.你可能想要这个:
INSERT INTO log (channel, nick, host, message, type timestamp, nickprefix)
VALUES (:channel, :nick, :host, :message, :type, :time, '');
Run Code Online (Sandbox Code Playgroud)
并且,请始终使用您的INSERTS指定列列表,并简单地省略数据库将为其提供值的任何值(这包括自动递增列和具有其他默认值的列).