在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为输出参数名 这些手册是我asp和php成功的关键,现在共享给家共同学习参考! 求无限(穷)目录方法 http://127.0.0.1:90/mewebsite/?action-login 请教关于PHP4+MySQL4的结果集翻页问题 谁有php的网站联盟的源码啊, 初学函数的困惑 PHP 4.3.10版与PEAR中的DB类有冲突??? 如何在一个窗口中刷新另一个窗口呢? 急急急,小问题,怎么在html的meta中实现转向功能,把它指引到另一页面上!???? php+json 快速读取数据 安装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为输出参数名