MySQL Innodb 会话表:更新查询找不到匹配项

发布于 2025-01-04 21:35:50 字数 547 浏览 4 评论 0原文

我的PHP会话是在MySQL数据库上实现的,会话表为InnoDB类型。

在 PHP 脚本的同一执行过程中,我注意到会话表中已添加新行,但我无法执行 UPDATE 语句。 mysql_info() 报告有 0 个匹配行,因此它从未找到它!但手动检查显示该行存在于表中。

问题是,如果我在后续 PHP 脚本中运行 UPDATE 语句,它就会起作用。

这也肯定与 InnoDB 类型有关,因为一旦切换到 MyISAM,它就可以正常工作。我是 InnoDB 表类型的新手,在处理 InnoDB 表时有什么需要了解的吗?行级锁定?

[编辑:运行 UPDATE 语句时 MySQL 也没有返回任何错误]

[编辑,SQL 查询示例]

"UPDATE session SET user_id='" . mysql_real_escape_string($user_id) . "' WHERE session_id='" . mysql_real_escape_string(session_id()) . "'";

非常感谢任何帮助! 谢谢。

My PHP sessions are implemented on a MySQL database, with the session table InnoDB type.

During the same execution of a PHP script, I note that a new row has been added in the session table but I'm unable to do an UPDATE statement. mysql_info() reports that there were 0 matched rows, so it never found it! But manual checks show the row exists in the table.

The thing is the UPDATE statement works if I run it in a subsequent PHP script.

It's also definitely has to do with the InnoDB type, as once switching to MyISAM, it works fine. I'm new to InnoDB table type, is there something that I need to know when dealing with InnoDB tables? row-level locking?

[Edit: There's also no errors returned by MySQL when running the UPDATE statement]

[Edit, example of SQL query]

"UPDATE session SET user_id='" . mysql_real_escape_string($user_id) . "' WHERE session_id='" . mysql_real_escape_string(session_id()) . "'";

Any help much appreciated!
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

两仪 2025-01-11 21:35:50

这可能是一个时间问题吗?

举个例子:
采取两个快速连续运行的 PHP 脚本(例如网站)。
其中一个脚本完成并开始写入会话数据,第二个脚本在会话数据完成写入之前启动,并从数据库读取“当前”会话信息。
使用 InnoDB,第二个脚本将获取旧的会话数据。

你不喜欢异步系统吗?

Could this be a timing issue?

As an example:
Take two PHP scripts that are run in rapid succession (for example a website).
One of the script completes and starts writing the session data, the second starts before the session data has completed writing and reads the 'current' session information from the DB.
With InnoDB, the second script would get the old session data.

Don't you love async systems.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文