在PHP中如果调用MySQL中已经写好的存储过程? http://www.phpchina.cn/code/2006/0616/517.html 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 mynamesucks(来了两年半了还是5个三角) 谢谢你,我在网上一搜出一大堆,都是这文章,可是我试过了,根本不行呀. 修改如下:mysql> delimiter //mysql> create procedure aa(out cnt int) -> begin -> select count(*) into cnt from mytable; -> end -> //Query OK, 0 rows affected (0.00 sec)在php中这样调用<?phpmysql_query("call aa(@c)");$res = mysql_query("select @c");$row = mysql_fetch_array($res);echo $row['@c'];?> 按照你的回复,我另建了存储过程,加上输出参数,可还是不行呀,<?$db =@MySQL_connect("localhost", "root","123456");@MySQL_select_db("test",$db);mysql_query("call aa(@c)");$res = mysql_query("select @c");$row = mysql_fetch_array($res);echo $row['@c'];echo "===<br>";$sql = "select count(*) from mytable";$result = MySQL_query($sql);$myrow = MySQL_fetch_array($result);if ($myrow){ echo $myrow[0];}?>运行输出结果为:===<br>33,存储过程部分没起作用. <?$db =@MySQL_connect("localhost", "root","123456");@MySQL_select_db("test",$db);mysql_query("call aa(@c)");$res = mysql_query("select @c");$row = mysql_fetch_array($res);print_r ($row);?>输出结果为:Array( [0] => [@a] => )数组是空的 Array( [0] => [@a] => )这里的@a不应该是@c吗? 是我换了名字试一下,拷贝错误,都一样,<?$db =@MySQL_connect("localhost", "root","123456");@MySQL_select_db("test",$db);mysql_query("call aa(@c)");$res = mysql_query("select @c");$row = mysql_fetch_array($res);print_r ($row);?>输出结果为:Array( [0] => [@c] => ) 不好意思,是我搞错了,我的存储过程语句错误了,select count(*) from mytable;应该改为select count(*) into outparr from mytable;注:outparr为输出参数名 【求助】apache的url重写的问题 php+extjs不显示数据的问题 新手求助个PHP代码 请问这个函数aspell_new是不是过时了在PHP显示这个函数没有定义? 求教一个关于PHP站点调试的问题 php5 是否存在mysqli_pconnect() 这个函数? PHP 连接MSSQL ,用UTF8提交到MSSQL,mssql 后台管理查询乱码问题? PHP有什么优点? 大家帮帮忙,关于session的问题 怎样刷新母窗口 安装Discuz的时候总是出现1251错误,把用户名改成root又没事 排序然后写入数据库,在线等
mysql> delimiter //
mysql> create procedure aa(out cnt int)
-> begin
-> select count(*) into cnt from mytable;
-> end
-> //
Query OK, 0 rows affected (0.00 sec)在php中这样调用
<?php
mysql_query("call aa(@c)");
$res = mysql_query("select @c");
$row = mysql_fetch_array($res);
echo $row['@c'];
?>
$db =@MySQL_connect("localhost", "root","123456");
@MySQL_select_db("test",$db);mysql_query("call aa(@c)");
$res = mysql_query("select @c");
$row = mysql_fetch_array($res);
echo $row['@c'];echo "===<br>";$sql = "select count(*) from mytable";
$result = MySQL_query($sql);
$myrow = MySQL_fetch_array($result);
if ($myrow){
echo $myrow[0];
}
?>运行输出结果为:
===<br>33,存储过程部分没起作用.
$db =@MySQL_connect("localhost", "root","123456");
@MySQL_select_db("test",$db);mysql_query("call aa(@c)");
$res = mysql_query("select @c");
$row = mysql_fetch_array($res);
print_r ($row);
?>输出结果为:Array
(
[0] =>
[@a] =>
)数组是空的
(
[0] =>
[@a] =>
)
这里的@a不应该是@c吗?
$db =@MySQL_connect("localhost", "root","123456");
@MySQL_select_db("test",$db);mysql_query("call aa(@c)");
$res = mysql_query("select @c");
$row = mysql_fetch_array($res);
print_r ($row);
?>输出结果为:Array
(
[0] =>
[@c] =>
)
应该改为
select count(*) into outparr from mytable;注:outparr为输出参数名