Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Warning:mysql select db() expects parameter 2 to be boolean

I am receiving warning :mysql_select_db() expects parameter 2 to be boolean

4:29 am on Oct 22, 2013 (gmt 0)

New User

joined:Oct 22, 2013
posts: 1
votes: 0

I am developing a software for online test in PHP for mobile phones.While, running question.php in windows ,I am getting
warning:select_mysql_db() expects parameter 2 to be resource ,boolean given in C://wamp/www/student/question.php on line 254.
The line number 254 is $db_result = mysql_select_db($database, $con) in my PHP code. Also I am getting:warning mysql_fetch_assoc() expects parameter 1 to be resource ,boolean given in C://wamp/www/student/question.php on line 367.The line number 367 is $sqlArr = mysql_fetch_assoc($sqlQuer).
My PHP code is given below.Any one please help me to solve this.Thanks in advance.

PHP Code

$user_name = "root";
$password = "root";
$database = "mydatabase";
$server = "localhost";
$con = mysql_connect($server, $user_name, $password);
$db_result = mysql_select_db($database, $con);

$sql = sprintf(
"SELECT * FROM question WHERE name = '%s'", mysql_real_escape_string($h)

$sqlQuer = mysql_query($sql);

$sqlArr = mysql_fetch_assoc($sqlQuer);
4:33 am on Oct 22, 2013 (gmt 0)

Senior Member from GB 

WebmasterWorld Senior Member brotherhood_of_lan is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Jan 30, 2002
votes: 2

Welcome to the forums sonya krishna,

It sounds like the errors are a result of no connection being established to the MySQL server at all, and since you have no warning/error checking, the script continues to show more warning messages.

Try changing it to
$con = mysql_connect($server, $user_name, $password) or die(mysql_error());

It should give you a more verbose reason as to why the server could not be connected to, usually it's because the server isn't where you specified it should be, or the username/password is wrong.