$link=@mysqli_connect($db_host,$db_username,$db_password,$db_databases); $sql="CREATE DATABASE world"; /* проверяем соединение */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } /* возвращаем имя текущей базы данных */ if ($result = mysqli_query($link, "SELECT DATABASE()")) { $row = mysqli_fetch_row($result); printf("Default database is %s.\n", $row[0]); mysqli_free_result($result); } /* изменяем текущую базу данных на world */ mysqli_select_db($link, "world"); /* возвращаем имя текущей базы данных */ if ($result = mysqli_query($link, "SELECT DATABASE()")) { $row = mysqli_fetch_row($result); printf("Default database is %s.\n", $row[0]); mysqli_free_result($result); } mysqli_close($link); 

Why doesn't the database change? The current database is displayed twice.

  • akh, and you executed request of $ sql on base creation? - pavelbel
  • Switch only to the existing database. And I see that you wrote the query: $ sql = "CREATE DATABASE world"; But where this base is created - I do not see. - Deonis

1 answer 1

Check what this string returns:

 mysqli_select_db($link, "world"); 

If FALSE , it means some kind of error. Maybe such a database is missing, or the user under which connect, do not have access rights to it.