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

Jones Joseph
  • 4,703
  • 3
  • 22
  • 40
santosh m
  • 17
  • 5
  • 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. – M. Eriksson May 18 '17 at 08:51
  • Can you update full code for above where have you used mysql_fetch_row in code? – Saurabh Parekh May 18 '17 at 08:53

0 Answers0