简体   繁体   English

PHP / MySQL中间歇性的“无数据库选择”?

[英]Intermittent “No Database Selected” in PHP/MySQL?

Have a PHP/MySQL form with a dropdown box containing a list of 350 names. 有一个带有下拉框的PHP / MySQL表单,其中包含350个名称的列表。 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". 当选择任何随机名称时,有时它会工作并从数据库中显示有关该名称的信息,有时表单会给出错误“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) 将/etc/my.cnf中的max_connections从200增加到2000(即使只有4-5个连接,这是一个使用率很低的服务器)
  • Changing mysql_pconnect to mysql_connect 将mysql_pconnect更改为mysql_connect
  • Adding the word true to this connection string: 将true添加到此连接字符串:

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

  • Changing the word require_once to require on this line: 在此行上将require_once一词更改为require:

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

  • Enabling MySQL & PHP query & error logging. 启用MySQL和PHP查询和错误记录。 (no errors logged) (没有记录错误)

Here is the code: [removed old bad code] 这是代码:[删除旧的坏代码]

Update: Working answer from Rob Apodaca below. 更新:Rob Apodaca的工作答案如下。

This line: mysql_select_db($database_mysql, $mysql); 这一行: 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 . 由于$database_mysql的值似乎没有改变,我将删除该行的所有实例并将其放在mysql_pconnect/mysql_connect line

My issue was with a database connection object (B) that was serialized within another serialized object (A). 我的问题是在另一个序列化对象(A)中序列化的数据库连接对象(B)。 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. 有时,根据在对象A被反序列化之前发生的事情,对象B将执行带有空数据库名称的mysql_select_db()调用,因为它已经丢失。

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. 我们用MySQL查询“ SELECT DATABASE() ”的结果回显了我们的代码,直到我们发现默认数据库的间歇性丢失发生的地方。 Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM