间歇性“未选择数据库”在 PHP/MySQL 中?

发布于 2024-08-31 09:34:50 字数 702 浏览 2 评论 0原文

有一个 PHP/MySQL 表单,其中包含一个包含 350 个名称的列表的下拉框。当选择任何随机名称时,有时它会起作用并且可以正常工作。显示数据库中有关该名称的信息,有时该表单会给出错误“未选择数据库”。

这是我尝试过的,因为我不是程序员,所以几乎抓住了稻草:将

  • /etc/my.cnf 中的 max_connections 从 200 增加到 2000 (即使只建立了 4-5 个连接,并且它是一个很少使用的服务器)
  • 将 mysql_pconnect 更改为 mysql_connect
  • 将单词 true 添加到此连接字符串:

    $mysql = mysql_pconnect($hostname_mysql, $username_mysql, $password_mysql, true) 或 trigger_error(mysql_error(),E_USER_ERROR);

  • 将此行中的单词 require_once 更改为 require:

    [?php require('/home/user/Connections/mysql.php'); ?]

  • 启用 MySQL 和PHP查询&错误记录。 (没有记录错误)

这里是代码:[删除了旧的错误代码]

更新:下面 Rob Apodaca 的工作答案。

Have a PHP/MySQL form with a dropdown box containing a list of 350 names. When any random name is selected, sometimes it works & displays info about that name from the database, and sometimes the form gives the error "No Database Selected".

Here's what I've tried, pretty much grasping at straws as I'm not a programmer:

  • Increasing max_connections in /etc/my.cnf from 200 to 2000 (even though only 4-5 connections are made and it's a lightly used server)
  • Changing mysql_pconnect to mysql_connect
  • Adding the word true to this connection string:

    $mysql = mysql_pconnect($hostname_mysql, $username_mysql, $password_mysql, true) or trigger_error(mysql_error(),E_USER_ERROR);

  • Changing the word require_once to require on this line:

    [?php require('/home/user/Connections/mysql.php'); ?]

  • Enabling MySQL & PHP query & error logging. (no errors logged)

Here is the code: [removed old bad code]

Update: Working answer from Rob Apodaca below.

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

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

发布评论

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

评论(2

海拔太高太耀眼 2024-09-07 09:34:51

此行: mysql_select_db($database_mysql, $mysql); 在您提供的脚本中出现多次。由于 $database_mysql 的值似乎没有改变,我将删除该行的所有实例并将其放置在 mysql_pconnect/mysql_connect 行之后。

This line: mysql_select_db($database_mysql, $mysql); appears more than once in your provided script. Since the value of $database_mysql does not appear to change, I would remove all of the instances of that line and place it just after the mysql_pconnect/mysql_connect line.

北陌 2024-09-07 09:34:51

我的问题是在另一个序列化对象 (A) 中序列化的数据库连接对象 (B)。有时,根据对象 A 反序列化之前发生的情况,对象 B 会使用空数据库名称执行 mysql_select_db() 调用,因为它已丢失。

我们在代码中散布了一些 MySQL 查询“SELECT DATABASE()”结果的回显,直到找到默认数据库间歇性丢失的位置。希望这有帮助!

My issue was with a database connection object (B) that was serialized within another serialized object (A). Sometimes, depending on what had happened prior to object A being unserialized, object B would perform a mysql_select_db() call with a null database name as it had been lost.

We littered our code with some echo's of the result of a MySQL query "SELECT DATABASE()" until we found where the intermittent loss of the default database was occurring. Hope this helps!

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