By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,406 Members | 1,470 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,406 IT Pros & Developers. It's quick & easy.

No database selected

P: n/a
I have identical names for the database, user and password on the local
machine and on the remote site. I also have identical tables and info in
the tables. It works perfectly on the local machine. On the remote site I
get "No Database Selected". It happens in the mysql_query call.

echo "ssLogin = " . $ssLogin . " ";
$LoginRS = mysql_query($LoginRS__query, $ssLogin) or die(mysql_error());
echo "LoginRS = " . $LoginRS;

This gives:
ssLogin = Resource id #3 No Database Selected

On both machines I have have a require file which is:

<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_ssLogin = "localhost";
$database_ssLogin = "the_database_name";
$username_ssLogin = "the_username";
$password_ssLogin = "the_password";
$ssLogin = mysql_pconnect($hostname_ssLogin, $username_ssLogin,
$password_ssLogin) or die(mysql_error());
?>

I thought it might be the $hostname_ssLogin, that it had to be something
else. However, if it is not localhost, then the mysql_pconnect fails.

Any ideas?

Shelly
Jul 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Shelly (sh*******@asap-consult.com) decided we needed to hear...
I have identical names for the database, user and password on the local
machine and on the remote site. I also have identical tables and info in
the tables. It works perfectly on the local machine. On the remote site I
get "No Database Selected". It happens in the mysql_query call.

echo "ssLogin = " . $ssLogin . " ";
$LoginRS = mysql_query($LoginRS__query, $ssLogin) or die(mysql_error());
echo "LoginRS = " . $LoginRS;

This gives:
ssLogin = Resource id #3 No Database Selected

On both machines I have have a require file which is:

<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_ssLogin = "localhost";
$database_ssLogin = "the_database_name";
$username_ssLogin = "the_username";
$password_ssLogin = "the_password";
$ssLogin = mysql_pconnect($hostname_ssLogin, $username_ssLogin,
$password_ssLogin) or die(mysql_error());
?>

I thought it might be the $hostname_ssLogin, that it had to be something
else. However, if it is not localhost, then the mysql_pconnect fails.

Any ideas?

Shelly

While your test machine may have only one (default) database, your
remote machine will probably require you to specify which db you
want to use... you can do this right after you connect with a call
such as
$status = mysql_select_db($database_ssLogin, $ssLogin);

As an aside, are you sure your webhost allows persistent connections?
I wouldn't have thought so, but a few might I suppose.

--
Dave <da**@REMOVEbundook.com>
(Remove REMOVE for email address)
Jul 17 '05 #2

P: n/a
"Dave" <da**@REMOVEbundook.com> wrote in message
news:7h************@fawlty.homelinux.net...
While your test machine may have only one (default) database, your
remote machine will probably require you to specify which db you
want to use... you can do this right after you connect with a call
such as
$status = mysql_select_db($database_ssLogin, $ssLogin);

As an aside, are you sure your webhost allows persistent connections?
I wouldn't have thought so, but a few might I suppose.
I had one already there:
mysql_select_db($database_ssLogin, $ssLogin);
$encryptedPassword = md5($_POST["password"]);
$LoginRS__query=sprintf("SELECT username, password, level, status
FROM ssusername WHERE username='%s' AND password='%s'",
get_magic_quotes_gpc() ? $loginUsername :
addslashes($loginUsername),
$encryptedPassword);
$LoginRS = mysql_query($LoginRS__query, $ssLogin) or die(mysql_error());

where it fails.

Here is a possiblity. Tell me what you think. On my local machine I am
running PHP5 but I think the server is running PHP4.x

Shelly


--
Dave <da**@REMOVEbundook.com>
(Remove REMOVE for email address)

Jul 17 '05 #3

P: n/a
Shelly (sh*******@asap-consult.com) decided we needed to hear...
"Dave" <da**@REMOVEbundook.com> wrote in message
news:7h************@fawlty.homelinux.net...
While your test machine may have only one (default) database, your
remote machine will probably require you to specify which db you
want to use... you can do this right after you connect with a call
such as
$status = mysql_select_db($database_ssLogin, $ssLogin);

As an aside, are you sure your webhost allows persistent connections?
I wouldn't have thought so, but a few might I suppose.


I had one already there:
mysql_select_db($database_ssLogin, $ssLogin);
$encryptedPassword = md5($_POST["password"]);
$LoginRS__query=sprintf("SELECT username, password, level, status
FROM ssusername WHERE username='%s' AND password='%s'",
get_magic_quotes_gpc() ? $loginUsername :
addslashes($loginUsername),
$encryptedPassword);
$LoginRS = mysql_query($LoginRS__query, $ssLogin) or die(mysql_error());

where it fails.

Here is a possiblity. Tell me what you think. On my local machine I am
running PHP5 but I think the server is running PHP4.x

Shelly

I wouldn't have thought PHP version should matter in this case - more
likely its a MySQL issue.

I would try checking the return value from mysql_select_db. If you get
false then that might indicate a permissions problem. e.g. with my host
when I create a MySQL user I then have to associate that user with any
database I want to use it with, as a seperate step - if thats not done
then even though I can connect fine, selecting a database will fail
until I associate the user...

--
Dave <da**@REMOVEbundook.com>
(Remove REMOVE for email address)
Jul 17 '05 #4

P: n/a
*** Shelly wrote/escribió (Sun, 22 May 2005 22:43:11 -0400):
mysql_select_db($database_ssLogin, $ssLogin);


No error checking here?

From manual:

usage:

bool mysql_select_db ( string database_name [, resource link_identifier ] )

Returns TRUE on success or FALSE on failure.
--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Jul 17 '05 #5

P: n/a

"Alvaro G Vicario" <al******************@telecomputeronline.com> wrote in
message news:19*****************************@40tude.net...
*** Shelly wrote/escribió (Sun, 22 May 2005 22:43:11 -0400):
mysql_select_db($database_ssLogin, $ssLogin);


No error checking here?

From manual:

usage:

bool mysql_select_db ( string database_name [, resource
link_identifier ] )


This the generated code from Dreamweaver. I'll add a check.

Shelly
Jul 17 '05 #6

P: n/a
> "Alvaro G Vicario" <al******************@telecomputeronline.com> wrote in
message news:19*****************************@40tude.net...
*** Shelly wrote/escribi? (Sun, 22 May 2005 22:43:11 -0400):
mysql_select_db($database_ssLogin, $ssLogin);


No error checking here?

From manual:

usage:

bool mysql_select_db ( string database_name [, resource
link_identifier ] )


This the generated code from Dreamweaver. I'll add a check.

Shelly


I added:

if (!mysql_select_db($database_ssLogin, $ssLogin)) {
echo "The mysql_select_db returned FALSE";
}

and it echoed. You are correct. It is failing in mysql_select_db. No what
do I do?

Shelly
Jul 17 '05 #7

P: n/a
Shelly wrote:
I added:

if (!mysql_select_db($database_ssLogin, $ssLogin)) {
echo "The mysql_select_db returned FALSE";
}

and it echoed. You are correct. It is failing in mysql_select_db. No what do I do?


Add:

echo mysql_error();

To find out what the problem is.

--
Oli

Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.