Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未捕获异常';PDO异常';带有消息';SQLSTATE[HY000]:一般错误:20数据类型不匹配';in/media/Data/Documenten/PHP/µ;Bot/index.php:100_Php_Sql_Sqlite_Pdo - Fatal编程技术网

未捕获异常';PDO异常';带有消息';SQLSTATE[HY000]:一般错误:20数据类型不匹配';in/media/Data/Documenten/PHP/µ;Bot/index.php:100

未捕获异常';PDO异常';带有消息';SQLSTATE[HY000]:一般错误:20数据类型不匹配';in/media/Data/Documenten/PHP/µ;Bot/index.php:100,php,sql,sqlite,pdo,Php,Sql,Sqlite,Pdo,我一直收到这个错误消息。它所说的数据类型是文本,要插入的数据是文本,所以我看不出有什么问题 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: c

我一直收到这个错误消息。它所说的数据类型是文本,要插入的数据是文本,所以我看不出有什么问题

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
问题所在的代码块(第100行是该代码块的最后一行):

完整代码:

--

SQLite版本:SQLite 2.8.17-6.1ubuntu1

PHP版本:php5 common 5.3.6-13ubuntu3.2

我不知道SQLLITE,但在快速阅读文档并专门查找“:”属性后,我发现:

主机参数的名称

const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
sqlite3_bind_parameter_name(p,N)接口返回准备语句p中第N个SQL参数的名称。格式为“?NNN”或“:AAA”或“@AAA”或“$AAA”的SQL参数的名称分别为字符串“?NNN”或“:AAA”或“@AAA”或“$AAA”。换言之,姓名的一部分包括首字母“:”或“$”或“@”或“?”。形式为“?”且没有以下整数的参数没有名称,称为“匿名”或“匿名参数”

第一个主机参数的索引为1,而不是0

如果值N超出范围或第N个参数未命名,则返回NULL。返回的字符串始终采用UTF-8编码,即使在sqlite3_prepare16()或sqlite3_prepare16_v2()中最初将命名参数指定为UTF-16

因此,以下错误(查看#1中的消息)可能与文本中的“:”有关。试着从文本中删除它,看看会发生什么

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'、':请稍等,…)
2{main}我不知道您的模式,但我猜
id
是一个自动递增列,如下所示:

INSERT INTO log (id, channel, nick, host, message, type timestamp, nickprefix)
VALUES ('', :channel, :nick, :host, :message, :type, :time, '');
正在尝试将空字符串放入
id
。你可能想要这个:

INSERT INTO log (channel, nick, host, message, type timestamp, nickprefix)
VALUES (:channel, :nick, :host, :message, :type, :time, '');

并且,请始终在插入时指定列列表,只需省去数据库将为其提供值的任何值(包括自动递增列和具有其他默认值的列)。

如果指定列(
插入日志(…)值(…)
)桌子是什么样子的?像这样<代码>插入到日志(id、频道、尼克、主机、消息、类型时间戳、尼克引用)值(“”,:频道,:尼克,:主机,:消息,:类型,:时间,”)->显然不是->@muistooshort Nvm关于上面的评论,忘记了一个逗号。不管怎样,同样的问题。谢谢你,谢谢你!!!我花了5个小时浏览文档,联系了4个不同的人,但没有人知道问题出在哪里!大多数时候都是这样简单的:p我习惯MySQL,在这里你可以使用
'
作为一个自动增量字段。@RobinJ:MySQL最糟糕的事情是它鼓励坏习惯:)你也可以把它留给MySQL,所以把它去掉是一个好习惯。不过,使用PDO的道具比通常的mysql_this和mysql_this噪音要好得多。
INSERT INTO log (channel, nick, host, message, type timestamp, nickprefix)
VALUES (:channel, :nick, :host, :message, :type, :time, '');