第一步,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);
本文介绍了一个MySQL存储过程的创建方法,该过程用于查询多个表中时间戳的最小年份和最大年份,并展示了如何使用PHP来调用这个存储过程。通过实例代码,读者可以了解到在MySQL中定义存储过程的语法以及在PHP中连接数据库并执行存储过程的具体步骤。
1137

被折叠的 条评论
为什么被折叠?



