Are you just connecting or are running a query as well ?
The code below executes the connection and makes the check if there was error, in case of error will show the error message and finish, in case of success in the connection will show the success message and then close the connection with the database.
<?php
$link = mysqli_connect("HOST", "USUARIO", "SENHA", "BASE");
if (!$link) {
echo "Error: Falha ao conectar-se com o banco de dados MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
echo "Sucesso: Sucesso ao conectar-se com a base de dados MySQL." . PHP_EOL;
mysqli_close($link);
Updating
Follow the steps in the order:
1 - finish mysql:
sudo /usr/local/mysql/support-files/mysql.server stop
2 - Start it in safe mode:
sudo mysqld_safe --skip-grant-tables
3 - This will be a continuous command until the process is over, so open another shell/ terminal window and log in without a password as root:
mysql -u root
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NOVASENHA';
Change NOVAPASSWORD for a desired password and start Mysql
sudo /usr/local/mysql/support-files/mysql.server start
What code are you using to access and display the data? What page code does not render?
– Isac
So buddy, the connection code is as follows::
$conexao = mysqli_connect('localhost', 'root', '', 'php_alura');However I gave a Restart in apache and is now rendering the pages, but I can not connect to mysql. OBS: I can only move mysql through the panel using the permission of sudo, I believe you have some relationship, but I don’t know how to solve.– Carlos Roberto