Ho uno script PHP che uso per connettersi a un database MySQL. Collegamento tramite mysql_connect funziona perfettamente, ma quando si cerca con DOP ottengo il seguente errore:Non è possibile connettersi al server MySQL tramite PDO
SQLSTATE[HY000] [2005] Unknown MySQL server host 'hostname' (3)
il codice che uso per collegare è inferiore:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
$hostname_localhost ="hostname";
$database_localhost ="dbname";
$username_localhost ="user";
$password_localhost ="pass";
$user = $_GET['user'];
$pass = $_GET['pass'];
try{
$dbh = new PDO("mysql:host=$hostname_localhost;dbname=$database_localhost",$username_localhost,$password_localhost);
echo 'Connected to DB';
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $dbh->prepare("SELECT check_user_company(:user,:pass)");
$stmt = $dbh->bindParam(':user',$user,PDO::PARAM_STR, 16);
$stmt = $dbh->bindParam(':pass',$pass,PDO::PARAM_STR, 32);
$stmt->execute();
$result = $stmt->fetchAll();
foreach($result as $row)
{
echo $row['company_id'].'<br />';
}
$dbh = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
Grazie in anticipo
L'errore è abbastanza ovvio ... il nome host specificato non può essere risolto in un indirizzo IP. –
Dove si dice "hostname" si suppone di inserire * il proprio nome host o indirizzo IP del server * mySQL. –
Ho dimenticato di menzionare, sto usando gli indirizzi IP (e anche l'indirizzo IP è nell'errore) ma ho modificato i valori di proposito per motivi di sicurezza – user1337210