CentOS 6.4 PHP 5.3.3 MySQL 5.1.69 x86_64
mysql_stmt::fetch()
When executing fetch using a prepared statement, PHP yields error: PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 4294967296 bytes).
This occurs when a variable included in a SELECT statement used to create a temporary table is unset, whether or not the variable is otherwise set in the environment before the stored procedure is called. The variable must be set within the stored procedure. When a SELECT statement is used to return data in the temporary table to PHP, and PHP uses mysql_stmt::fetch() to access the data, PHP generates the above fatal error.
MySQL Code:
DELIMITER $$
CREATE PROCEDURE test_sp()
BEGIN
# uncomment below line, and PHP call to mysqli_stmt::fetch() works
# SET @status = 1;
# remove tmp table
DROP TABLE IF EXISTS tmp_table;
# CREATE TEMPORARY TABLE
CREATE TEMPORARY TABLE tmp_table
SELECT @status AS status;
SELECT * FROM tmp_table;
END $$
DELIMITER ;
PHP Code:
// obtain MySQL login info
require_once(MYSQLOBJ);
// initialize status
$status = "";
$db = new mysqli(
DB_HOST,
DB_USER,
DB_PASSWORD,
DB_NAME
);
$query = "CALL test_sp";
$stmt = $db->prepare($query);
$stmt->execute();
$stmt->bind_result( $status );
$stmt->store_result();
$stmt->fetch(); // PHP FATAL ERROR OCCURS HERE
$stmt->free_result();
$db->close();
print "<p>status = $status</p>
";
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…