php调去存储过程
2013-09-30 10:41
176 查看
第一步,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);
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);
相关文章推荐
- 关于thinkphp显示不出验证码
- php引用(&)详解及注意事项
- php 判断中文,英文,数字
- PHP getenv函数
- PHP strcasecmp函数
- PHP swfupload图片上传的实例代码
- php 判断是否是中文/英文/数字示例代码
- php json_encode值中大括号与花括号区别
- PHP 验证码不显示只有一个小红叉的解决方法
- PHP CURL CURLOPT参数说明(curl_setopt)
- PHP file_get_contents设置超时处理方法
- PHP设置一边执行一边输出结果的代码
- PHP中func_get_args(),func_get_arg(),func_num_args()的区别
- php中利用str_pad函数生成数字递增形式的产品编号
- PHP文件上传主要代码讲解
- php mysql_real_escape_string函数用法与实例教程
- PHPCMSV9 更换域名后,要做的操作
- 九个PHP很有用的功能
- 20 你应该知道的PHP库
- PHPCMS V9类调用方法