Apparently missing parameters for connection. Below is the method I do.
<?php
$DATABASE_HOST = 'localhost';
$DATABASE_USER = 'root';
$DATABASE_PASS = '';
$DATABASE_NAME = 'nome_do_banco';
$con = mysqli_connect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS, $DATABASE_NAME);
if ( mysqli_connect_errno() ) {
header('HTTP/1.1 500 Internal Server Error');
header('Content-Type: application/json');
die(json_encode(array('message' => 'Falha ao Conectar ao MySQL: ' . mysqli_connect_error(), 'code' => 599)));
exit('Falha ao Conectar ao MySQL: ' . mysqli_connect_error());
}
?>
Here is also an example of the site itself php.
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
But I believe that this method only works in php5 if you are using php7 the first and best choice. I hope I have helped.
"Undefined Function mysql_connect()" has nothing to do with connection error, the function is that there is no.
– Bacco