Intermittent "No database selected" in PHP / MySQL?

It has the form of PHP / MySQL with a drop-down list containing a list of 350 names. When a random name is selected, sometimes it works and displays information about that name from the database, and sometimes the form gives the error "No database selected."

Here is what I tried, quite clutching at a straw, as I am not a programmer:

  • Increase max_connections in /etc/my.cnf from 200 to 2000 (even if only 4-5 connections are made and this is a slightly 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);

  • Change the required word require_once in this line:

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

  • Including MySQL and PHP queries and error logging. (errors are not logged)

Here is the code: [old bad code removed]

Update: A working answer from Rob Apodaki is below.

+3
source share
2 answers

This line: is mysql_select_db($database_mysql, $mysql);displayed more than once in the provided script. Since the value $database_mysqldoes not change, I delete all instances of this line and place it immediately after mysql_pconnect/mysql_connect line.

+3
source

(B), (A). , , , A , B mysql_select_db() , .

MySQL "SELECT DATABASE()", , . , !

0

Source: https://habr.com/ru/post/1744371/


All Articles