存储过程很简单,就两条语句begin
select * from tt1;
select "hello the world!";
end
PHP:$row=mysql_fetch_row($res);
echo $row[0];
//mysql_free_result($res);//****
$row=mysql_fetch_row($res);
echo $row[0];
但上面的PHP代码只能读出第一个结果集,如果取消****那行注释,返回错误:
Warning: mysql_fetch_row(): 2 is not a valid MySQL result resource ......怎样才能把两个结果集都读出来?谢谢。

解决方案 »

  1.   


    while($row = mysql_fetch_row($res)){
      var_dump($row);
    }
      

  2.   

    给你一个完整的示例参考,照着做就可以了,注意多结果集操作中每取完一个结果集后必须close()!!存储过程代码DELIMITER $$;DROP PROCEDURE IF EXISTS `test`.`sp_test`$$CREATE PROCEDURE `test`.`sp_test` ()
    BEGIN
        select * from `user`.`user` limit 0, 50;
        select count(0) as `count` from `user`.`user`;
    END$$DELIMITER ;$$php 代码
    $rows = array ();   
    $db = new mysqli('127.0.0.1','root','123456','user');   
    if (mysqli_connect_errno()){   
        $this->message('Can not connect to MySQL server');   
    }   
    $db->query("SET NAMES UTF8");   
    if($db->real_query("call sp_test()")){   
        do{   
            if($result = $db->store_result()){   
                while ($row = $result->fetch_assoc()){   
                    array_push($rows, $row);   
                }   
                $result->close();   
            }   
        }while($db->next_result());   
    }   
    $db->close(); 
     
      

  3.   

    服务器不支持mysqli,
    有没有不使用mysqli 的代码?谢谢.
      

  4.   

    $result=msql_query("call Pro_test()");
    $row=mysql_fetch_array($result);
    echo $row[0];
      

  5.   


    $row=mysql_fetch_row($res);
    print_r($row);
    mysql_free_result($res);//****
    $row=mysql_fetch_row($res);
    print_r($row);
    //这样不行?
      

  6.   

    不行.
    "Warning: mysql_fetch_row(): 2 is not a valid MySQL result resource "