Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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


..

What I have tried:

PHP
<?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;
}


?>
Posted
Comments
Jassim Rahma 28-Dec-19 17:23pm    
Just to add, I have no problem running the sp_signin on the database using CALL sp_signin and I am getting the correct result.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900