PHP connection string Offline

1

I'm trying to connect offline to a MySQL database, but I'm not getting it.

The code is on my machine, I've already tried IIS and XAMPP but every time I try to connect, it displays an error. Here's the connection string I'm using:

$host = ""; //computador onde o servidor de banco de dados esta instalado
$user = ""; //seu usuario para acessar o banco
$pass = ""; //senha do usuario para acessar o banco
$banco = ""; //banco que deseja acessar

$conexao = mysql_connect($host,$user,$pass);
if (!$conexao)
{
die('Erro: ' . mysql_error());
} else {
echo "Conectou";
}
mysql_select_db($banco);

Here is the error that appears:

  

Error: mysqlnd can not connect to MySQL 4.1+ using the old insecure authentication.

     

Please use an administration tool to reset your password with the command SET PASSWORD = PASSWORD ('your_existing_password').

     

This will store a new, more secure, hash value in mysql.user. If this user is used in other scripts executed by PHP 5.2 or earlier you might need to remove the old-passwords flag from your my.cnf file.

Does anyone know why this happens?

    
asked by anonymous 29.09.2014 / 20:37

1 answer

2

Review your connection information.

Default information for connecting to MySQL

Host: localhost or 127.0.0.1

User: root

Password: Default password is blank anyway

Then your default connection would look like this:

$host = "localhost"; //computador onde o servidor de banco de dados esta instalado
$user = "root"; //seu usuario para acessar o banco
$pass = ""; //senha do usuario para acessar o banco
$banco = "test"; //banco que deseja acessar

$conexao = mysql_connect($host,$user,$pass);

Considerations

  • Consider changing from mysql_connect to mysqli_connect
  • Consider using a class to manage your connection ( ConnectionMSi )
  • 29.09.2014 / 21:22