php调去存储过程

第一步,mysql端建存储过程

DELIMITER $$
create procedure mintime()
begin
select min(year(htime)) as minnian,max(year(htime)) as maxnian FROM cas_beijing_event UNION
select min(year(htime)) as minnian,max(year(htime)) as maxnian FROM cas_hebei_event UNION
select min(year(htime)) as minnian,max(year(htime)) as maxnian FROM cas_shanghai_event UNION
select min(year(htime)) as minnian,max(year(htime)) as maxnian FROM cas_tianjin_event UNION
select min(year(htime)) as minnian,max(year(htime)) as maxnian FROM cas_bjx_event UNION
select min(year(htime)) as minnian,max(year(htime)) as maxnian FROM cas_tjx_event;
end$$
DELIMITER ;

2.php调去存储过程

<?php

$db = mysqli_connect('127.0.0.1', 'root', '');
mysqli_select_db($db, 'cass');

$db->query("set names 'gb2312'");

$rs = array();
$result = $db->real_query("call mintime3(0,0)");
do {
    if ($result = $db->store_result()) {
        while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
            array_push($rs, $row);
        }
        $result->free();
    }
} while ($db->next_result());
var_dump($rs);

上一篇:js兼容方法:通过样式名获取元素,byClass


下一篇:HDU 4632 Palindrome subsequence (区间DP)