Forum Moderators: coopster

Message Too Old, No Replies

More problems: now with mysql_select_db

Triple checked: correct database name, but still error

         

mlkarie

11:41 am on Nov 25, 2003 (gmt 0)

10+ Year Member



Having got through to the server (with mysql_connect), I now get a "cannot open database" error on the mysql_select_db command.

I've triple checked the database name on the control panel of the server. I'm also assuming that I'm through to the server successfully, as there is no "access denied" error, or any other kind of error after the mysql_connect command.

The database definitely exists, and I can access it in PHPMyAdmin with the username and password which works in the mysql_connect command.

With the following code specified:

<code>
$mysql_database="mydatabase";
$mysql_username="username";
$mysql_password="password";

$link = mysql_connect("33.99.90.27:1103",$mysql_username,$mysql_password) or die ("Unable to connect to SQL server");
</code>

....I've tried the following syntaxes

mysql_select_db($mysql_database, $link) or die ("Unable to select database");
mysql_select_db($mysql_database) or die ("Unable to select database");
mysql_select_db("actual_name", $link) or die ("Unable to select database");

All of them fail to select the database. Either I'm doing something wrong, or the database doesn't exist on that server. But so far all the mistakes have been mine, not the server administrator's, so I'm rather loathe to ask him what to do next.

Can anyone help?

Thanks
mlkarie

Birdman

11:51 am on Nov 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When you use phpmyAdmin, the header at the top should read:

'Database ******** running on ********'

The string after 'Database' should be what you use in your mysql_select_db() line.

mlkarie

12:31 pm on Nov 25, 2003 (gmt 0)

10+ Year Member



Thanks, I've checked that. I do have the correct string.

Distel

12:54 pm on Nov 25, 2003 (gmt 0)

10+ Year Member



Is it possible to post the exact code you have in that file (except privileged information of course)? Sometimes, it can be a small thing (I had some weird problems some moments ago, and it turned out I was using one case of $mysql_select_db instead of mysql_select_db ;)

Birdman

1:01 pm on Nov 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this(after fixing connection string). This script will list all dbs.

<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
$db_list = mysql_list_dbs($link);

while ($row = mysql_fetch_object($db_list)) {
echo $row->Database . "\n";
}
?>

charlier

2:34 pm on Nov 25, 2003 (gmt 0)

10+ Year Member



You might also want to check the connection 'source' vis a vis phpmyadmin and your script. If phpmyadmin is on the same machine it may be connecting as 'localhost' while your script (even if on the same machine) may be showing a different connection source (ie the server name of the machine). Different permissions may then be granted for the database(s).

Also, if you are on another machine (not the one running the mysql database I mean) could it be a firewall issue?

Does the mysql_error function return anything?

mlkarie

9:36 am on Nov 27, 2003 (gmt 0)

10+ Year Member



Hi everyone, and sorry for the delay

I ran a script containing mysql_list_dbs, and the reply was a humongous list of databases, but without the database that I'm trying to connect to.

This hosting company uses two servers, and I'm connecting to the IP address and port as specified on their control panel.

Either my database is sitting on the other server, or the there is something wrong with the rights.

However, having run mysql_list_dbs and seen what's there, I now feel I can contact the server administrator without feeling stupid, thanks to your help.

BTW, the entire script that I'm using, is as follows:

<?php

$mysql_database="mydb";
$mysql_username="user";
$mysql_password="pword";

$link = mysql_connect("33.23.67.12:5678",$mysql_username,$mysql_password) or die ("Unable to connect to SQL server");
mysql_select_db($mysql_database, $link) or die ("Unable to select database");

?>

mlkarie

3:22 pm on Nov 27, 2003 (gmt 0)

10+ Year Member



Have solved the problem. I had two rather similar error messages, and erroneously attributed the error message to the mysql_select statement, instead of to a later statement. Found the problem in the later statement, and everything was okay. (Learnt a lesson: be careful with wording of error messages.)

How stupid can one get? Maybe it's time for a holiday...

figment88

4:08 pm on Nov 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I find it is useful for debugging to a line like:

echo $link . ": " . mysql_errno() . ": " . mysql_error() . "\n<br>";