在php中存储过程调用后,SQL Query无法运行

时间:2013-03-28 00:42:38

标签: php mysql stored-procedures

在我的PHP代码中,我在普通SQL之前调用存储过程(link:SELECT * FROM TABLE;)查询运行。对于该存储过程运行但正常SQL无法运行。我在两种情况下都使用mysql_query()。但是当我运行普通的SQL时,它会同时运行。

我有一个具有mysql_query()

的类dataManager

这是我的代码:

require_once 'DL/DataManager.php'; 
require_once 'utils/Utils.php';
require_once 'DL/class/event/Event.php';
$Utils = new Utils();
$obj = new Event();

$result = array();

$result = $obj->get_all_event_data("NULL"); //Query =  "CALL events_all_data(" . $ID . ");";

echo date("y-m-d h:i:s")."<br />";

echo $Utils->getString_UserName_ByUserID( "23" )."<br />"; // Not Run   Query = SELECT  `USER_NICK` FROM  `USER_INFO` WHERE  `USER_ID` ='".$string ."';";

DataManager.php

public function openConnection()
{
    $this->connection = mysql_connect($this->HostName, $this->UserName, $this->PassWord);
        if (!$this->connection)
        {
                return mysql_error();
        }
        mysql_select_db($this->DataBase);
        return $this->connection;
} 

执行sql查询

public function retrieveData($Query = "")
{
    //$Query = mysql_real_escape_string($Query);
    //echo "DB retriveData query : ".$Query. " <br />";
    $data = mysql_query($Query);
    $num_rows = mysql_num_rows($data);
    //echo "db ret number : ".$num_rows." asdas: ". "\n";


    if($num_rows)
    {
        $this->Data = array();
        //$i = 0;
        while ($mat[] = mysql_fetch_row($data));
            //echo $mat[$i++][2]."<br />";
        $this->Data = $mat;
        //print_r($this->Data);
    //$result = $this->getArrayTranspose($mat);
    }
    else
    {
        $this->Data = NULL;
    }

    //return $result;

}

连接关闭

public function closeConnection()
{
    if(!$this->connection)
    {
        mysql_close ();

        return ;
    }
    else if($this->connection == NULL)
    {
        mysql_close ();

        return ;
    }
    else if(!isset($this->connection))
    {
        mysql_close ();

        return ;
    }
    else if(is_resource($this->connection))
    {
        mysql_close($this->connection);
        return ;
    }
    else
    {
        //mysql_close();
    }

}

2 个答案:

答案 0 :(得分:1)

在您的代码中,您没有在任何地方提及$string 尝试运行这样的查询以获取错误代码。

 $mat=mysql_query($query) or die (mysql_error());

试一试。

答案 1 :(得分:0)

Mysql错误是:命令不同步;你现在不能运行这个命令