When trying to connect to the database, an error appears: Warning: mysqli_select_db () expects parameter 1 to be mysqli, string given. In the database selection function, first decree. connection, and then the name of the database (if not mistaken, it should be)

<? function connect() { $db_host = "localhost"; // Сервер $db_user = "root"; // Имя пользователя $db_password = ""; // Пароль пользователя $db_name = "yii"; // Имя базы данных // Подключаемся к серверу $conn = mysqli_connect($db_host, $db_user, $db_password) or die("<p>1 Невозможно подключиться к СУБД</p>"); $db = mysqli_select_db($conn, $db_name) or die("<p>2 Невозможно подключиться к базе данных</p>"); $query = mysqli_query("set names utf8", $conn) or die("<p>3 Невозможно выполнить запрос к базе данных</p>"); } ?> 
  • Try instead of $conn = mysqli_connect($db_host, $db_user, $db_password) prescribe $conn = mysqli_connect($db_host, $db_user, $db_password, $db_name) - Dmitriy Kondratiuk

1 answer 1

 $query = mysqli_query("set names utf8", $conn) or die("<p>3 Невозможно выполнить запрос к базе данных</p>"); 

replaced by

 $query = mysqli_query($conn, "set names utf8") or die("<p>3 Невозможно выполнить запрос к базе данных</p>");