Intermittent "No Database Selected" in PHP/MySQL?
        Posted  
        
            by ANE
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by ANE
        
        
        
        Published on 2010-05-06T15:50:18Z
        Indexed on 
            2010/05/06
            19:18 UTC
        
        
        Read the original article
        Hit count: 355
        
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.
© Stack Overflow or respective owner