运行存储过程的PhpMyAdmin通过接口工作,但作为查询运行不起作用

运行存储过程的PhpMyAdmin通过接口工作,但作为查询运行不起作用,php,mysql,phpmyadmin,Php,Mysql,Phpmyadmin,最奇怪的事情发生了: 这是在PhpMyAdmin MySql接口中编写的我的SP: Begin /* event id and number of event's albums*/ Declare eventId varchar(20); /*Declare numberOfAlbums int default 0; */ /* get event id */ Set eventId = decodeEventCode(eventCode);

最奇怪的事情发生了:

这是在PhpMyAdmin MySql接口中编写的我的SP:

Begin
    /* event id and number of event's albums*/
    Declare eventId varchar(20);
    /*Declare numberOfAlbums int default 0;     */
    /* get event id */
    Set eventId = decodeEventCode(eventCode);

    If (eventKey Is Not Null And eventKey <> '' And getEventKey(eventId,facebookId) = eventKey) Then                
        /* get number of albums */
        /*Set numberOfAlbums = (Select Count(eventId) From Albums Where Event_Id = eventId);*/
        /* return active album */
        Select Users.Facebook_Id, Users.Facebook_Access_Token, Users.Facebook_Expires, getUserTime(facebookId) As User_Local_Time, Events.Name as Event_Name, Events.Place As Event_Place, Events.Start_Time, Events.End_Time, Albums.Album_Id, Albums.Number_Of_Pictures/*, numberOfAlbums As Album_Count*/
        From Albums
        Inner Join Events
        On Events.Event_Id = Albums.Event_Id
        Inner Join Users
        On Users.Facebook_Id = Events.Facebook_Id
        Where Albums.Event_Id = eventId
        Order By Albums.Number_Of_Pictures
        Limit 1;
        /* if no rows was found return 0*/      
        If (Found_Rows() = 0) Then      
            select 0 as status;
        End If;
    Else
        Select 0 as status;
    End If;
End
这将生成查询:

Call getEventActiveAlbum('10230910','42','613714903')

知道为什么会这样吗?当从PHP代码运行脚本时,我没有得到任何回报…

我将根据需要的空间编写答案

也许您的框架/类使query$this->queryDb使用的是较旧的mysql,而不是较新的mysqli。为了好玩,试试看

$conn = mysqli_connect("hostname", "user", "password", "db", "port");      
$result = mysqli_query(
  $conn,
  "Call getEventActiveAlbum('$eventCode','$eventKey','$facebookId')"
)
or die("failed: " . mysqli_error());

ps在mysql中没有大师

我遇到过类似的问题。我想这是由于分隔符的问题。尝试使用原始mysql控制台而不是phpMyadmin创建存储过程。

好的,我解决了它:

问题在于select语句

当没有结果时——这个问题中提到的问题发生了,但是,当有结果时——效果很好

我重写了存储过程并使用Select计数来确定是否应该尝试运行复杂的Select语句,如下所示:

Begin
    /* declare eventId and number of albums for this event */
    Declare eventId int;
    Declare numberOfAlbums int default 0;

    /*get event id */
    Set eventId = decodeEventCode(eventCode);
    /* if event id is valid, and event key is correct */
    If (eventId <> -1 And eventKey Is Not Null And getEventKey(eventId,facebookId) <> 0) Then
        /*count the number of albums in this event */
        Set numberOfAlbums = (Select Count(Album_Id) From Albums Where Event_Id = eventId); 
        /* if there are albums in these event - return the active one*/
        if (numberOfAlbums > 0) Then
            Select Events.Name as Event_Name, Events.Place as Event_Place, Events.Start_Time, Events.End_Time,
                   getUserTime(Users.Facebook_Id) as User_Local_Time, Users.Facebook_Id, Users.Facebook_Access_Token, Users.Facebook_Expires,
                    Albums.Album_Id, Albums.Number_Of_Pictures, numberOfAlbums as Albums_Count
            From Albums
            Inner Join Events
            On Albums.Event_Id = Events.Event_Id
            Inner Join Users
            On Events.Facebook_Id = Users.Facebook_Id
            Where Albums.Event_Id = eventId
            Order By Albums.Number_Of_Pictures 
            Limit 1;
        /* if there are no albums in the event - return event details */
        Else
            Call getEventDetails(eventCode);
        End If;
    /* if the request is not valid - return 0 as status */
    Else    
        Select 0 as status;
    End If;     
End

php代码在哪里?php代码是个问题。。。问题是phpmyadmin接口正确地执行了函数,但是当试图复制和粘贴他生成的查询时,它的工作原理是不同的……是的,但是没有看到它是如何在php中实现的,谁又能知道它哪里出错了。phpmyadmin已经正确调用了存储过程,但是您在php中的实现没有正确调用,因此imo的问题在于如何在php中调用它。粘贴php代码我将添加我的调用,但正如我前面提到的,即使在phpmyadmin接口中,当尝试在其SQL查询接口中运行查询时(与他们用来运行sp的查询相同),也无法运行。。。在这件事上,在我进入我的php代码之前,这不是一个失败,我还有很多其他的工作存储过程。。我的怀疑是,我的find_行的条件可能没有返回我期望的结果,并且没有调用select语句。。
Begin
    /* declare eventId and number of albums for this event */
    Declare eventId int;
    Declare numberOfAlbums int default 0;

    /*get event id */
    Set eventId = decodeEventCode(eventCode);
    /* if event id is valid, and event key is correct */
    If (eventId <> -1 And eventKey Is Not Null And getEventKey(eventId,facebookId) <> 0) Then
        /*count the number of albums in this event */
        Set numberOfAlbums = (Select Count(Album_Id) From Albums Where Event_Id = eventId); 
        /* if there are albums in these event - return the active one*/
        if (numberOfAlbums > 0) Then
            Select Events.Name as Event_Name, Events.Place as Event_Place, Events.Start_Time, Events.End_Time,
                   getUserTime(Users.Facebook_Id) as User_Local_Time, Users.Facebook_Id, Users.Facebook_Access_Token, Users.Facebook_Expires,
                    Albums.Album_Id, Albums.Number_Of_Pictures, numberOfAlbums as Albums_Count
            From Albums
            Inner Join Events
            On Albums.Event_Id = Events.Event_Id
            Inner Join Users
            On Events.Facebook_Id = Users.Facebook_Id
            Where Albums.Event_Id = eventId
            Order By Albums.Number_Of_Pictures 
            Limit 1;
        /* if there are no albums in the event - return event details */
        Else
            Call getEventDetails(eventCode);
        End If;
    /* if the request is not valid - return 0 as status */
    Else    
        Select 0 as status;
    End If;     
End