MIdNight 0 Denunciar post Postado Janeiro 14, 2011 Olá gente, eu criei uma classe para a conexão SQL, nela tenho esta função: Function Connect() { $this->handle = MySQL_Connect($this->host, $this->user, $this->pass); If (!$this->handle) { Die('Não foi possível iniciar a conexão SQL: ' . mysql_error()); } } No construtor eu informo os valores que serão assumidos como host, user e pass. Quando utilizo a função dá o seguinte erro: Access denied for user 'USUARIO'@'HOST' (using password: YES) Porém se eu tento acessar o PhpMyAdmin utilizando o mesmo usuário e a mesma senha, eu consigo acessar normalmente, podem me ajudar? Compartilhar este post Link para o post Compartilhar em outros sites
Vinicius Borsato 0 Denunciar post Postado Janeiro 14, 2011 Amigo tente postar a classe completa ou então pelo menos o contrutor pra gente poder ver. Não sei se te ajuda, mais vou colocar aqui uma função bem simples (praticamente a mesma coisa que você fez) para fazer essa conexão: private function conectar() { $this->connect = mysql_connect($this->host, $this->user, $this->pass); mysql_select_db($this->db, $this->connect); // já define o bd aqui também return $connect; } Acredito que retornando a conexão fica mais fácil para tratar esse err. Compartilhar este post Link para o post Compartilhar em outros sites
MIdNight 0 Denunciar post Postado Janeiro 14, 2011 Não acho necessário postar toda mas ok, taí: <?php /* Classe reservada para a conexão MySQL */ Class MySQL { Private $host, $user, $pass, $db; Public $handle; Function __construct($a, $b, $c) { $this->host = $a; $this->user = $b; $this->pass = $c; } Function Connect() { $this->handle = MySQL_Connect($this->host, $this->user, $this->pass); If (!$this->handle) { Die('Não foi possível iniciar a conexão SQL: ' . mysql_error()); } } Function SelectDB($a) { $this->db = $a; If(! Empty($this->handle)) { mysql_select_db($this->db, $this->handle); Return (1); } Else { Return (0); } } Function _Exit() { MySQL_Close($this->handle); } } ?> Compartilhar este post Link para o post Compartilhar em outros sites
gugoan 0 Denunciar post Postado Janeiro 14, 2011 Esse erro geralmente indica que você ta errando usuario e/ou senha, ou o mysqld não pode rsolver o nome de máquina do cliente. O banco de dados está no mesmo computador??? Compartilhar este post Link para o post Compartilhar em outros sites
MIdNight 0 Denunciar post Postado Janeiro 14, 2011 Não, eu uso o IP para me conectar, a senha está correta, já verifiquei, consigo acessar normalmente pelo PhpMyAdmin. Compartilhar este post Link para o post Compartilhar em outros sites
C. Medeiros 0 Denunciar post Postado Janeiro 14, 2011 Certamente seu usuário não deve permitir conexões remotas, se seu banco está na mesma máquina utilize "localhost" ao invés do IP, caso contrário ao acessar o phpmyadmin clique em privilégios e altere as permissões ou crie um usuário para tal finalidade Compartilhar este post Link para o post Compartilhar em outros sites
MIdNight 0 Denunciar post Postado Janeiro 14, 2011 Opa, obrigado, vi que o servidor estava como local nos usuários, criarei um novo e posto o resultado. @Edit Agora estou tendo este erro: Warning: mysql_connect() [function.mysql-connect]: Premature end of data (mysqlnd_wireprotocol.c:554) in C:\Program Files\xampp\htdocs\********\mysql.php on line 20 Warning: mysql_connect() [function.mysql-connect]: OK packet 1 bytes shorter than expected in C:\Program Files\xampp\htdocs\********\mysql.php on line 20 Warning: mysql_connect() [function.mysql-connect]: mysqlnd cannot 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, and 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 in C:\Program Files\xampp\htdocs\********\mysql.php on line 20 N�o foi poss�vel iniciar a conex�o SQL: mysqlnd cannot 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, and 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 Compartilhar este post Link para o post Compartilhar em outros sites
Gabem MVP 0 Denunciar post Postado Janeiro 14, 2011 Tenta com localhost Compartilhar este post Link para o post Compartilhar em outros sites
MIdNight 0 Denunciar post Postado Janeiro 15, 2011 É uma conexão remota, não é local. Compartilhar este post Link para o post Compartilhar em outros sites