开发者

PHP PDO: nextRowset on multiple rowsets on a prepared statement

开发者 https://www.devze.com 2023-03-31 10:32 出处:网络
I have the PHP script below which uses PDO to prepare and call a MySQL stored procedure. The stored procedure returns 2 rowsets. The 1st contains 25 rows. The 2nd contains 1 row. I can\'t seem to get

I have the PHP script below which uses PDO to prepare and call a MySQL stored procedure. The stored procedure returns 2 rowsets. The 1st contains 25 rows. The 2nd contains 1 row. I can't seem to get the nextRowset to fetch the 2nd rowset. I know the stored procedure works because it was working when I was using mysqli_next_result. Thanks...

1.) What am I doing wrong?

2.) Is there a more efficient or secure way to write this script? I use the same format for all my ajax calls. I know I can bind the $_GET parameters to a data type (string, integer) to be a little more secure but the stored procedure already does that.

<?php
header('Content-type: application/json');
session_start();
if(isset($_SESSION['Logged_In'])){
    $r=array();
    require('db.inc');
    $s=$c->prepare("CALL get_records({$_SESSION['User_ID']},?,?,?)");
    $s->execute($_GET);
    do{$r[]=$s->fetchAll(PDO::FETCH_NUM);}while($s->nextRowse开发者_运维问答t());
    $c=null;
    echo json_encode($r);
}
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消