0

I am trying to create a database if the database is not present, but it shows some error.

This the code that I am using:

{ 
    $conn = mysql_connect($dbhost, $dbuser, $dbpass);
    if(!$conn)
    {
        die('Failed to connect to server: ' . mysql_error());
        exit;
    }

    $db_selected = mysql_select_db($dbname);

    if(!$db_selected)
    {
        $db_selected = " CREATE DATABASE $dbname ";
    }
}

This is the error that i get:

mysql_fetch_row() expects parameter 1 to be resource, boolean given on line 2 Reading one value from empty results

2
  • Don't use the deprecated and insecure mysql_*-functions. They have been deprecated since PHP 5.5 (in 2013) and were completely removed in PHP 7 (in 2015). Use MySQLi or PDO instead. Commented May 18, 2017 at 8:51
  • Can you update full code for above where have you used mysql_fetch_row in code? Commented May 18, 2017 at 8:53

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.