http://www.phpchina.cn/code/2006/0616/517.html

解决方案 »

  1.   

    mynamesucks(来了两年半了还是5个三角) 谢谢你,我在网上一搜出一大堆,都是这文章,可是我试过了,根本不行呀.
      

  2.   

    修改如下:
    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'];
    ?>
      

  3.   

    按照你的回复,我另建了存储过程,加上输出参数,可还是不行呀,<?
    $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,存储过程部分没起作用.
      

  4.   

    <?
    $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] => 
    )数组是空的
      

  5.   

    Array
    (
        [0] => 
        [@a] => 
    )
    这里的@a不应该是@c吗?
      

  6.   

    是我换了名字试一下,拷贝错误,都一样,<?
    $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] => 
    )
      

  7.   

    不好意思,是我搞错了,我的存储过程语句错误了,select count(*) from mytable;
    应该改为
    select count(*) into outparr from mytable;注:outparr为输出参数名