mysql_select_db(): supplied argument is not a valid MySQL-Li

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
menkaur
Forum Newbie
Posts: 2
Joined: Wed Feb 10, 2010 8:12 am

mysql_select_db(): supplied argument is not a valid MySQL-Li

Post by menkaur »

Hey. Here's my code:

Code: Select all

<html>
    <head>
        <title>check this out page</title>
    </head>
<body>
<?php
 
$host = 'localhost';
$user = 'xxx';
$pass = 'yyy';
$db = mysql_connect($host, $user, $pass) || die("something went wrong");
 
$dbName = "menkaur_moviesite";
 
echo $dbName;
 
mysql_select_db($dbName, $db);
 
?>
</body>
</html>
when i run that, i get following error message:
Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/menkaur/public_html/php/index.php on line 17

what's the problem?
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: mysql_select_db(): supplied argument is not a valid MySQL-Li

Post by aravona »

This gave the same error you had even with my own details (not shown below - those are fakies ;) ):

Code: Select all

<?php
 
$host = 'localhost';
$user = 'myuser';
$pass = 'mypass';
$db = mysql_connect($host, $user, $pass) || die("something went wrong");
 
$dbName = "mytestdb";
 
echo $dbName;
 
mysql_select_db($dbName, $db);
 
?>
 
Using this didnt:

Code: Select all

<?php
 
$host = 'localhost';
$user = 'myuser';
$pass = 'mypass';
$db = mysql_connect($host, $user, $pass) OR die("something went wrong");
 
$dbName = "mytestdb";
 
echo $dbName;
 
mysql_select_db($dbName, $db);
 
?>
 
Nor did:

Code: Select all

<html>
    <head>
        <title>check this out page</title>
    </head>
<body>
<?php
 
$host = 'localhost';
$user = 'myuser';
$pass = 'mypass';
$db = mysql_connect($host, $user, $pass)
 
$dbName = "mytestdb";
 
echo $dbName;
 
mysql_select_db($dbName, $db);
 
if (!$db) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
 
?>
</body>
</html>
Try the second one instead :) Though the third works well too :)
menkaur
Forum Newbie
Posts: 2
Joined: Wed Feb 10, 2010 8:12 am

Re: mysql_select_db(): supplied argument is not a valid MySQL-Li

Post by menkaur »

) thanks! it works.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: mysql_select_db(): supplied argument is not a valid MySQL-Li

Post by AbraCadaver »

menkaur wrote:) thanks! it works.
Of course it works. OR is not the same as ||. OR is evaluated after the $db = mysql_connect($host, $user, $pass) assignment and the || is evaluated before. See: http://www.php.net/manual/en/language.o ... edence.php
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply