Dmitry Makovetskiyd
Dmitry Makovetskiyd

Reputation: 7053

MySQL table doesn't exist when it does exist

I have this query:

mysql_select_db('scanner');
$query = "SELECT * FROM scanner.proxy ORDER BY RAND() LIMIT 20";
$result = mysql_query($query) or die(mysql_error());

it tells me:'scanner.proxy ' doesnt exist.. even though I do have it the table with the database. It is weird, cause my other queries work..but this one doesnt.

UPADTE:

Event when I put this:

$user='root';
            $user='root'
        $password='<removed_password>';
        $dbname = 'scanner';
        $host = 'localhost';
        $link = mysql_connect($host, $user, $password) or die (mysql_error());

mysql_select_db($dbname, $link) or die (mysql_error());

it gives me this...

Unknown database 'scanner'

But I can see the scanner database in the phpmyadmin

Even when I type in phpmyadmin the sql statement SHOW TABLES FROM 'scanner'

it says it cant find scanner

Upvotes: 0

Views: 8828

Answers (5)

user2448048
user2448048

Reputation: 31

$db_host = 'localhost:Port'; Specify port for localhost. I was facing the same problem and specifying the port solved the problem.

Upvotes: 0

JimK
JimK

Reputation: 21

We solved this problem which occurred when connecting to multiple remote MySQL databases within the same script by adding a re-connect method before every mysql_query statement. The re-connect method invoked both mysql_connect and mysql_select_db functions. We had previously tried setting the new link parameter to true in the connect statement(s) but We still got database errors and all kinds of funny behavior.

Upvotes: 2

Alfabravo
Alfabravo

Reputation: 7569

make sure the user you use to connect has enough rights to query that table. Perhaps that table was created by another user.

EDIT: Perhaps you need to grant access to scanner from a remote location. Running this sholud help on that.

GRANT ALL ON scanner.* TO your_user@'IP_ofServer_where_PHP_runs' IDENTIFIED BY 'PASSWORD';

Upvotes: 0

Nadir Sampaoli
Nadir Sampaoli

Reputation: 5555

You're missing the argument that specifies the connection (result of mysql_connect()) in your mysql_select_db() call:

$db_host = 'localhost';
$db_username = 'root';
$db_password = 'whatever';
$db_name = 'scanner';
$link = mysql_connect($db_host, $db_username, $db_password);
mysql_select_db($db_name, $link);

Upvotes: -1

em3ricasforsale
em3ricasforsale

Reputation: 352

You have set the $dbname = 'aws_backlinks', but you are trying to connect to a different database within your query. Change your connection string to include this db instead or just connect to the server and set your database at the time of the query.

Upvotes: 0

Related Questions