Home php Throws mysql_connect error in PHP

Throws mysql_connect error in PHP




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;";

 Lorem ipsum dolor sit amet, lorem ipsum dolor sit amet, lorem ipsum dolor sit amet, oplorem ipsum, dolor sit amet, l ormem pidasoioiasdfosadufosau

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 ("", "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;
echo "MySQL connection established!" ... PHP_EOL;
echo "Server info:". mysqli_get_host_info ($ link). PHP_EOL;
mysqli_close ($ link);

http://php.net/manual/en/function.mysqli -connect.php

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions