Jump to content

No Database Selected


wmguk

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.....

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)  

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.