wmguk Posted November 26, 2009 Share Posted November 26, 2009 Hi Guys, This is a new one on me I have a DB, setup and installed, with the username and password sorted, however on my website I get ERROR: No Database Selected My Connection: <?php ob_start(); session_start(); //---------------------Connnection-------------------------------------------// $db_usr = "taxbust1_mike"; $db_pwd = "NR192DA"; $db_host = "localhost"; $db_name = "taxbust1_tax"; $myconn = mysql_pconnect($db_host,$db_usr,$db_pwd) or die("Can not connect"); mysql_select_db($db_name,$myconn); //--------------------------------------------------------------------------// ?> Head of the page <?php include "includes/dbconn.php"; if (!$myconn) { die( 'Could not connect: ' . mysql_error() ); } $sql = "SELECT * FROM news WHERE CO = 1 ORDER BY date ASC limit 2"; $result = mysql_query( $sql ) or die( "<strong>Query Error</strong>: " . mysql_error() . "<br><strong>Query</strong>: $sql<br><br>" ); $sql2 = "SELECT * FROM news WHERE CO = 2 ORDER BY date ASC limit 2"; $result2 = mysql_query( $sql2 ) or die( "<strong>Query Error</strong>: " . mysql_error() . "<br><strong>Query</strong>: $sql2<br><br>" ); ?> news is a table on the database and it has content... Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/183034-no-database-selected/ Share on other sites More sharing options...
nethnet Posted November 26, 2009 Share Posted November 26, 2009 This is a common error people run into when going from developing locally to publishing online. Check to make sure that there is no auto-appended prefix on your database name (some webservers to this). Also, this is sometimes caused by MySQL overload. Check with your webhost to see if there are any reported MySQL outages on the server. This has happened to me before and the solution was nothing more than waiting overnight for the problem to be resolved. Quote Link to comment https://forums.phpfreaks.com/topic/183034-no-database-selected/#findComment-965993 Share on other sites More sharing options...
Mchl Posted November 26, 2009 Share Posted November 26, 2009 Why do you think you should use persistent connections? Quote Link to comment https://forums.phpfreaks.com/topic/183034-no-database-selected/#findComment-965995 Share on other sites More sharing options...
wmguk Posted November 26, 2009 Author Share Posted November 26, 2009 I dont really know to be honest, on some of our scripts we use it, but on others we dont, i never really notice a difference. This has been like it for 3 days, and tech support say no faults logged. I've checked usernames and passwords, and indeed table names etc, and all are correct. I'm just lost on this..... Quote Link to comment https://forums.phpfreaks.com/topic/183034-no-database-selected/#findComment-965997 Share on other sites More sharing options...
nethnet Posted November 26, 2009 Share Posted November 26, 2009 Taken from the PHP manual: Warning Using persistent connections can require a bit of tuning of your Apache and MySQL configurations to ensure that you do not exceed the number of connections allowed by MySQL. As you stated, some pages use persistent connections and some don't. I would revert all connections back to the regular mysql_connect() and see if that doesn't fix the problem. Also, there is a big difference between the two. The major difference that I expect is impacting your script is the fact that mysql_pconnect() does not explicitly close its connections. And since you said you are interchanging the two connections, you could very easily exceed the max connection limit. Quote Link to comment https://forums.phpfreaks.com/topic/183034-no-database-selected/#findComment-965998 Share on other sites More sharing options...
PFMaBiSmAd Posted November 26, 2009 Share Posted November 26, 2009 Your mysql_select_db() function call has no error checking logic on it, so how do you know if it is working or failing? Something like the following would be in line with what you doing in the rest of the code - mysql_select_db($db_name,$myconn) or die("Could not select database: $db_name" . mysql_error()); tech support say no faults logged.Do you know for a fact that your error_reporting/log_errors/error_log setting are set so that all php detected errors are being logged? For debugging purposes, I would recommend adding the following two lines of code immediately after your first opening <?php tag in your main file - ini_set("display_errors", "1"); error_reporting(E_ALL); The following code in your main file won't do anything because if the connection fails, your code dies before reaching it ($myconn won't ever be false at that point in the main code) - if (!$myconn) Quote Link to comment https://forums.phpfreaks.com/topic/183034-no-database-selected/#findComment-966016 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.