Fórum Conectando remotamente com mysql #449816
29/07/2013
0
Ele gera vários erros.
Porém os dados estão corretos.
Alguém pode me dar um help, minha hospedagem é Hostgator
PS: já habilitei o mysql remoto, consigo acessar normalmente pelo navicat
define(''HOST'',''www.site.com'');
define(''DB'',''bancodedados'');
define(''USER'',''usuario'');
define(''PASS'',''senha'');
$conexao = ''mysql:host=''.HOST.'';dbname=''.DB;
try{
$conecta = new PDO($conexao,USER,PASS);
$conecta->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
}catch (PDOexception $error_conecta){
echo htmlentities(''Erro ao conectar ''.$error_conecta->getMessage());
}
Paulo Sérgio
Curtir tópico
+ 0Posts
29/07/2013
William
Você está usando aspas simples ou duplas, fiquei em dúvida no seu post?
Gostei + 0
30/07/2013
Paulo Sérgio
define("HOST","www.site.com.br");
define("DB","db");
define("USER","user");
define("PASS","pass");
$conexao = "mysql:host=".HOST.";dbname=".DB;
try{
$conecta = new PDO($conexao,USER,PASS);
$conecta->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
}catch (PDOexception $error_conecta){
echo htmlentities('Erro ao conectar '.$error_conecta->getMessage());
}
aparece os seguintes erros
Warning: PDO::__construct() [<a href='pdo.--construct'>pdo.--construct</a>]: Premature end of data (mysqlnd_wireprotocol.c:553) in D:\wamp\www\alternativa-online\teste.php on line 10
Warning: PDO::__construct() [<a href='pdo.--construct'>pdo.--construct</a>]: OK packet 1 bytes shorter than expected in D:\wamp\www\alternativa-online\teste.php on line 10
Erro ao conectar SQLSTATE[HY000] [2000] 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
Gostei + 0
31/07/2013
Paulo Sérgio
Gostei + 0
31/07/2013
Paulo Sérgio
Gostei + 0
01/08/2013
Paulo Sérgio
Gostei + 0
13/08/2013
William
Gostei + 0
13/08/2013
Marcio Araujo
Gostei + 0
04/09/2013
Adilson Rumao
$conecta = mysql_connect('endereco_do_servidor', 'usuario', 'senha')
or die('Erro ao conectar o mySQL!');
$db = mysql_select_db('banco_de_dados')
or die('Erro ao conectar o Banco de Dados!');
mysql_set_charset('utf8',$conecta);
mysql_query("SET NAMES 'utf8'");
mysql_query("SET character_set_connection=utf8");
mysql_query("SET character_set_client=utf8");
mysql_query("SET character_set_results=utf8");
Pode não ser o melhor método de conexão, mas por hora resolveu. Mais pra frente quando for terminar o projeto estou pensando em mudar para PDO.
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)