Script:

<?php$sdb_name = "gateser8";$user_name = "gateser8";$user_password = "**********";$db_name = "gateser8";if (!$link = mysql_connect($sdb_name, $user_name, $user_password)) { echo "<br>Не могу соединиться с сервером базы данных!<br>"; exit();}if (!mysql_select_db($db_name, $link)) { echo "<br>Не могу выбрать базу данных<br>"; exit();}$str_sql_query = "SELECT * FROM product";if (!$result = mysql_query($str_sql_query, $link)) { echo "<br>Не могу выполнить запрос<br>"; exit();}while ($mas = mysql_fetch_row($result)) { foreach ($mas as $field) { echo $field . " "; } echo "<br>";}mysql_close($link);?> 

Produces "I can not connect to the database server!"

    5 answers 5

    1. Try first to make sure that the database is running: on the database server: ps ax | grep mysql
    2. if the server is running - try to log in from the console (or phpmyadmin :)) mysql -h hostname -u user_name db_name -p
    3. I think the problems with the second paragraph, because like php-mysql module is already there.
       <?php$host = "localhost";// или тот ip, который указан в параметрах на хостинге$user_name = "gateser8";$user_password = "**********";$db_name = "gateser8";if (!mysql_connect($host, $user_name, $password)) { echo "Cannot connect to MySQL!"; exit;}mysql_select_db($db_name);mysql_set_charset('utf8');//Ну это на всякий пожарный...//$result = mysql_query($str_sql_query);//$link - не нужен, запросы будут выполняться с последним открытым соединением?> 

        Apparently, the php script cannot access the MySQL. Either MySQL itself is not installed, or the database 'gateser8' was not entered there, or the password or user to access the "gateser8" is incorrectly spelled out.

        • MySQL is on the server, the database is stored there in phpMyAdmin. The password and user are correct. From other sources, I found out that in mysql_connect the first parameter should be the hostname example: "locsalhost" or "127.0.0.1" - Olichch

        Tolley, I did not understand something, but your database is localhost or ip mysql_connect ('localhost', '..', '..'). :-)

          here is a working script trying it

            < ?php $link = mysql_connect('localhost', 'username', 'здесь вставить пароль'); if (!$link) { die('Ошибка соединения: ' . mysql_error()); } if (!mysql_ select_db("username")) { echo "Ошибка выбора базы данных mydbname: " . mysql_error(); exit; } $sql = "SELECT * FROM `dle_post` ORDER BY RAND() LIMIT 3"; $result = mysql_query($sql); if (!$result) { echo "Ошибка выполнения запроса: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "Запрос не вернул данных."; exit; } while ($row = mysql_fetch_assoc($result)) { echo '<li>'; echo $row["xfields"]; echo '</li>'; } mysql_free_result($result); mysql_close($link); ? >