How to connect to the database?
mysql_connect ("localhost", 'root') or die ('& lt; h1 & gt; Error to connect MySQL & lt; / h1 & gt; ');
echo "& lt; p & gt; You connect MySQL & lt; / p & gt;";
Answer 1, authority 100%
It is enough to get into the documentation:
http://php.net/manual/en/function.mysql -connect.php
Warning This extension has been deprecated since PHP 5.5.0, and
removed in PHP 7.0.0. Use MySQLi or PDO_MySQL instead.
From this we can conclude that your version of php
is just 7
.
Using mysqli_connect ()
:
$ link = mysqli_connect ("127.0.0.1", "my_user", "my_password", "my_db");
if (! $ link) {
echo "Error: Unable to connect to MySQL." ... PHP_EOL;
echo "Error code errno:". mysqli_connect_errno (). PHP_EOL;
echo "Error text:". mysqli_connect_error (). PHP_EOL;
exit;
}
echo "MySQL connection established!" ... PHP_EOL;
echo "Server info:". mysqli_get_host_info ($ link). PHP_EOL;
mysqli_close ($ link);