php调用mysql存储过程
2023-06-13 09:13:53 时间
前面转载了一篇《php调用mysql存储过程的文章》经过测试,发现文章中的方法似乎不可行!
调用带有select语句的存储过程就出现 PROCEDURE p can"t return a result set in the given context的错误。google了半天,在mysql官网上找到一些说法,db_mysql的模块不支持存储过程调用,解决方法是用db_mysqli。测试了一下,果然可以了。
用法比较简单,没啥好说的,从网上copy一段代码吧:
<?php
/* Connect to a MySQL server */
$link = mysqli_connect(
"localhost", /* The host to connect to */
"root", /* The user to connect as */
"root", /* The password to use */
"db_name"); /* The default database to query */
if (!$link) {
printf("Can"t connect to MySQL Server. Errorcode: %s\n", mysqli_connect_error());
exit;
}
/* Send a query to the server */
if ($result = mysqli_query($link, "call se_proc("crm")")) {
/* Fetch the results of the query */
while( $row = mysqli_fetch_array($result) ){
echo ($row[0]. "--------- SR. " . $row[1] . "
");
}
/* Destroy the result set and free the memory used for it */
mysqli_free_result($result);
}
/* Close the connection */
mysqli_close($link);
?>
郁闷的是费了半天劲搞出来的存储过程效率居然不如以前- -
调用带有select语句的存储过程就出现 PROCEDURE p can"t return a result set in the given context的错误。google了半天,在mysql官网上找到一些说法,db_mysql的模块不支持存储过程调用,解决方法是用db_mysqli。测试了一下,果然可以了。
用法比较简单,没啥好说的,从网上copy一段代码吧:
<?php
/* Connect to a MySQL server */
$link = mysqli_connect(
"localhost", /* The host to connect to */
"root", /* The user to connect as */
"root", /* The password to use */
"db_name"); /* The default database to query */
if (!$link) {
printf("Can"t connect to MySQL Server. Errorcode: %s\n", mysqli_connect_error());
exit;
}
/* Send a query to the server */
if ($result = mysqli_query($link, "call se_proc("crm")")) {
/* Fetch the results of the query */
while( $row = mysqli_fetch_array($result) ){
echo ($row[0]. "--------- SR. " . $row[1] . "
");
}
/* Destroy the result set and free the memory used for it */
mysqli_free_result($result);
}
/* Close the connection */
mysqli_close($link);
?>
郁闷的是费了半天劲搞出来的存储过程效率居然不如以前- -
相关文章
- MySQL连接URL:快速获取方法(mysql链接url)
- MySQL分布式数据库搭建指南(mysql分布式数据库搭建)
- MySQL存储网站URL的方法(mysql存url)
- 网页连接MySQL:创建一个数据连接的桥梁(网页连接mysql)
- MySQL脚本文件:轻松自动执行查询(mysql脚本文件)
- 管理MySQL多行数据操作指南(mysql多行数据)
- MySQL外连接:学习如何连接表(mysql外关联)
- 操作求和运算的MySQL数据技巧(mysql数据求和)
- 优化MySQL 慢查询优化:精确到每一步(mysql慢查询)
- 从MySQL到PHP:展示表格数据(php显示mysql表)
- 机制MySQL存储过程锁定机制:保护数据安全(mysql存储过程锁)
- MySQL建表:快速搭建数据存储容器(mysql建表)
- PHP使用mysql.so扩展连接MySQL数据库(phpmysql.so)
- MySQL如何建库和设置编码?(mysql建库设置编码)
- MySQL查看执行计划:优化你的查询效率(mysql查看执行计划)
- MySQL在ARM上的移植实践(mysql移植arm)
- MySQL数据同步导入Redis存储(mysql导入redis)
- MySQL的行最大长度问题,如何避免数据存储限制?(mysql行最大长度)
- 燕十八大佬带你复习MySQL,让你深入理解数据存储和查询技术(燕十八mysql复习)
- MySQL安装指南:快速开始!(mysql安装)
- MySQL 持久保存你的命令(mysql保存命令)
- MySQL中的文本存储方式(text mysql)
- MySQL中实现原子操作的方式(mysql原子操作)
- MySQL中存储大数据的BLOB类型详解(mysql中blob线)
- Ceph技术助力MySQL存储架构变革(Ceph和mysql)
- MySQL常见函数前三函数(mysql中前三函数)
- PHP与MySQL实现三表关联操作(mysql三表关联pHP)
- 深入剖析MySQL多连接下的事务管理(mysql不同连接的事务)
- MySQL实现两个字段求和(mysql 两字段求和)
- MySQL 数据库存储条数的上限(mysql上限存储条数)