When I run this php file shows me the error SQLSTATE [HY000]: General error
. Why?
function Gethotspots($db) {
$regId = $_GET['regId'];
$sql = $db->prepare("INSERT INTO notificaciones (regId) VALUES ('" . $regId . "')");
$sql->execute();
$i = 0;
$pois = $sql->fetchAll(PDO::FETCH_ASSOC);
if (empty($pois)) {
$response["productos"] = array();
}
else {
foreach ($pois as $poi) {
$poi["actions"] = array();
$response["productos"][$i] = $poi;
$i++;
}
}
return $response["productos"];
}
$dbhost = "localhost";
$dbdata = "anuncios";
$dbuser = "root";
$dbpass = "";
try {
$db = new PDO("mysql:host=$dbhost; dbname=$dbdata", $dbuser, $dbpass, array(
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$response = array();
$response["productos"] = Gethotspots($db);
if (empty($response["productos"])) {
$response["errorCode"] = 20;
$response["errorString"] = "Ningun producto encontrado.";
} // if
else {
$response["errorCode"] = 0;
$response["errorString"] = "Todo correcto";
}
$jsonresponse = json_encode($response);
header('Access-Control-Allow-Origin: *');
echo $jsonresponse;
$db = null;
} catch (PDOException $e) {
echo $e->getMessage();
}
Thanks all!