多个用户在php中使用mysql连接
我正在制作一个网站,需要访问 MySQL 数据库中的数据,代码是用 PHP 编写的。
这是我现在的连接调用:
$connection = mysql_connect("url", "username", "password", true);
$db_select = mysql_select_db("db_name", $connection);
多个用户将同时使用该网站,并且所有用户都将同时访问数据库。 用户1需要显示他的购买情况,用户2需要相同的信息等等......
现在,如果一个用户访问该网站,一切都很好。但是,如果两个用户尝试同时访问该网站,第二个用户将收到应用程序错误 (Facebook)。
我假设问题是第二个用户尝试在第一个崩溃的用户建立的同一连接上访问数据库。但是,我将 new_link
设置为 true
,所以我不确定为什么这仍然不起作用。有什么我没有想到的吗?
I am making a website that needs to access a data from a MySQL database, with the code written in PHP.
This is my connection call right now:
$connection = mysql_connect("url", "username", "password", true);
$db_select = mysql_select_db("db_name", $connection);
Multiple users will be using the website at once, and all of them will be accessing the database at the same time. User1 needs to have his purchases displayed, and user2 needs the same etc...
Right now if one user goes on the site, everything is fine. However, if two users try and access the site at the same time, the second user will get an application error (Facebook).
I am assuming the problem is that this second user tries to access the database on the same connection made by the first user which crashes. However, I set the new_link
to true
, so I'm not sure why this still isn't working. Is there something I am not thinking of?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的假设是错误的。每个用户实际上使用不同的 mysql 连接。
Your assumption is wrong. Each user actually uses different connection to mysql.