0

我必须遵循代码:

http://www.nomorepasting.com/getpaste.php?pasteid=22987

如果PHPSESSID不在表中,则REPLACE INTO查询工作正常,但是如果PHPSESSID存在,则执行调用成功,但 sqlstate 设置为“HY000”,这不是很有帮助,$_mysqli_session_write->errno并且 $_mysqli_session_write->error都是空的,并且数据列不会更新。

我相当确定问题出在我的脚本中,因为REPLACE INTO无论表中是否存在手动执行 from mysql 都可以正常工作PHPSESSID

4

3 回答 3

1

您为什么要在会话打开功能中进行准备?我不相信 write 函数在会话期间被调用一次以上,因此在公开场合准备它对您没有多大帮助,您不妨在会话写入中这样做。

无论如何,我相信您在表名之后和列列表之前需要一些空格。如果没有空格,我相信 mysql 会表现得好像您在尝试调用名为 session() 的不存在的函数一样。

REPLACE INTO session (phpsessid, data) VALUES(?, ?)

MySQL 认为 'COUNT ( )' 和 'COUNT( )'之间没有区别

有趣的是,当我在 mysql CLI 中运行以下命令时,我似乎得到了不同的结果。

mysql> select count (*);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*)' at line 1
mysql> select count(*);
+----------+
| count(*) |
+----------+
|        1 | 
+----------+
1 row in set (0.00 sec)
于 2008-12-24T09:25:41.423 回答
1

REPLACE INTO executes 2 queries: first a DELETE then an INSERT INTO. (So a new auto_increment is "By Design")

I'm also using the REPLACE INTO for my database sessions, but I'm using the MySQLi->query() in combination with MySQLI->real_escape_string() in stead of a MySQLi->prepare()

于 2009-01-11T12:44:38.297 回答
0

因此,事实证明,使用 REPLACE 还存在其他我不知道的问题:

Bug #10795: REPLACE reallocates new AUTO_INCREMENT (Which according to the comments is not actually a bug but the 'expected' behaviour)

As a result my id field keeps getting incremented so the better solution is to use something along the lines of:

 INSERT INTO session(phpsessid, data) VALUES('{$id}', '{$data}')
     ON DUPLICATE KEY UPDATE data='{$data}'

This also prevents any foreign key constraints from breaking and potential causing data integrity problems.

于 2008-12-31T23:08:08.857 回答