Hi,

I am getting General Error but can't find the reason.

The error I am getting is:

PDOException: SQLSTATE[HY000]: General error in /home/domain.com/api/signin.php:40
Stack trace:
#0 /home/domain.com/api/signin.php(40): PDOStatement->fetch()
#1 {main}Connection failed: SQLSTATE[HY000]: General error

Here is my code:

<?php
  header("Content-Type: application/json");

  if (isset($_SERVER['HTTP_ORIGIN'])) {
    header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
    header('Access-Control-Allow-Credentials: true');
    header('Access-Control-Max-Age: 86400');    // cache for 1 day
  }

  error_reporting(E_ALL);
  ini_set('display_errors', 1);
  
  $email = $_GET["email"];
  $salt = $_GET["salt"];
  $hash = $_GET["hash"];
  
  $mysql_host		=  "mysql:host=mysql.domain.com;dbname=myDB";
  $mysql_user		=  "myUser";
  $mysql_password	=  "myPassword";
  $mysql_options 	=  array
  (
	PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
  );

  // $mysql_connection;
  $mysql_connection = new PDO($mysql_host, $mysql_user, $mysql_password, $mysql_options);
  $mysql_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

try
{
  $mysql_query = $mysql_connection->prepare('CALL sp_signin(:param_email, :param_salt, :param_hash, :param_ip)');
  $mysql_query->bindParam(':param_email', $email, PDO::PARAM_STR);
  $mysql_query->bindParam(':param_salt', $salt, PDO::PARAM_STR);
  $mysql_query->bindParam(':param_hash', $hash, PDO::PARAM_STR);
  $mysql_query->bindParam(':param_ip', $_SERVER['REMOTE_ADDR'], PDO::PARAM_STR);
  $mysql_query->execute();
  
  $jsonData = array();

  while($mysql_row = $mysql_query->fetch())
  {
      $jsonData[] = $mysql_row;
  }
  
  echo json_encode($jsonData, JSON_NUMERIC_CHECK);
}
catch (PDOException $e)
{
    echo $e;
}
?>

    Looks like the fetch() is failing, so I might start by checking what the execute() statement returned. (Maybe the stored procedure is choking on something?)

      How can I check that? my stored procedure runs perfectly when I run it directly on the server

        Write a Reply...