I'm using a free hosting solution for my MySQL database. However, when I try to connect to it through my PHP code it throws me a uncaught PDOException error and my access is denied. I can't seem to find why the connection is denied as my credentials are correct.
I'm using Ionic 2 framework, if that helps.
Error:
<b>Fatal error</b>: Uncaught PDOException: SQLSTATE[HY000] [1045] Access denied for user 'sql10181809'@'153.92.0.10' (using password: YES) in /storage/ssd5/403/2053403/public_html/escanerproducto.php:33
Stack trace:
#0 /storage/ssd5/403/2053403/public_html/escanerproducto.php(33): PDO->__construct('mysql:host=sql1...', 'sql10181809', '\xE2\x81\xA0\xE2\x81\xA0\xE2\x81\xA0dfFf6l...')
#1 {main}
thrown in <b>/storage/ssd5/403/2053403/public_html/escanerproducto.php</b> on line <b>33</b><br />
PHP connection code:
<?php
@$db = new PDO("mysql:host=sql10.freesqldatabase.com;dbname=sql10181809", "sql10181809", "PASS");
if($db){
$sql = "select * from producto WHERE
codigo_barra='" . $codigodebarra . "'";
$query = $db->prepare($sql);
$query->execute();
$query->setFetchMode(PDO::FETCH_NUM);
if($fila = $query->fetch()){
$nombre = $fila[2];
$resultados_finales = array("nombre"=>$nombre);
echo json_encode($resultados_finales);
}
else{
$resultados_finales = array("mensage"=>"error");
echo json_encode($resultados_finales);
}
}
else {
$resultados_finales = array('mensage' => "ERROR.");
echo json_encode($resultados_finales);
};
?>