1

I am trying to execute a PHP script which I have hosted on my VPS Server, running Ubuntu 14.04. Here is the code for that script:

    <?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
header('Content-Type: application/json');
require_once("db_connection.php");

$emailAddress = $_POST['EmailAddress'];
if (isset($emailAddress)) {

    $getAthleteID = $connectionObject->prepare("CALL GetAthleteById(?)");
    $getAthleteID->bindParam(1, $emailAddress, PDO::PARAM_STR);
    $getAthleteID->execute();
    if ($getAthleteID->rowCount() > 0) {
        $resultAthlete = $getAthleteID->fetch(PDO::FETCH_ASSOC);
        $athleteID = $resultAthlete['UserID'];
        $getAthleteID->closeCursor();

        $getAthleteStats = $connectionObject->prepare("CALL GetAthleteRuns(?)");
        $getAthleteStats->bindParam(1, $athleteID, PDO::PARAM_INT);
        $getAthleteStats->execute();
        if ($getAthleteStats->rowCount() > 0) {
            $result = $getAthleteStats->fetch(PDO::FETCH_ASSOC);
            $getAthleteStats->closeCursor();
            echo json_encode($result);
        } else {
            $getAthleteStats->closeCursor();
            echo "Error300";
        }
    } else {
        $getAthleteID->closeCursor();
        echo "Error400";
    }
    }

When I send in an E-Mail address to the script, I get an error about not being able to run the queries:

Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.' in /var/www/html/ibaleka/get_athlete_runs.php:19

In my db_connection file, I have the following set:

$connectionObject = new PDO($host, $username, $password);
$connectionObject->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$connectionObject->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$connectionObject->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);

Not sure what I am doing wrong... Could it be an issue with the VPS Server?

Okuhle
  • 842
  • 3
  • 14
  • 31
  • take a look here. i think it will help you: http://stackoverflow.com/questions/17434102/causes-of-mysql-error-2014-cannot-execute-queries-while-other-unbuffered-queries – andrew Jul 25 '16 at 11:22

0 Answers0