0

最奇怪的事情刚刚发生:

这是我用 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

这就是使用 PhpMyAdmin 中的“执行”按钮的结果的样子。注意接口生成的查询:

这是使用结果的方式

这是我复制/粘贴的确切查询,并在 PhpMyAdmin SQL 查询界面中使用以对其进行测试 - 它没有选择任何表示未找到表的内容:

这是我复制/粘贴的确切查询,并在 PhpMyAdmin SQL 查询界面中使用以对其进行测试-它没有选择任何内容,说明没有找到表...

这是我从我的 php 代码中调用的:

/**
 * Get the current active event album with all his details
 * @param $eventCode string the event code of the event
 * @param $eventKey string the user's special event key
 * @param $facebookId string user's facebook id
 * @return array the details of the active album
 */
function getEventActiveAlbum($eventCode,$eventKey,$facebookId)
{
    return $this->queryDb("Call getEventActiveAlbum('$eventCode','$eventKey','$facebookId')");
}

生成查询:

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

知道为什么会这样吗?从 PHP 代码运行脚本时,我什么也得不到……

4

3 回答 3

1

好的,我解决了:

问题出在 select 语句上。

当没有结果时 - 这个问题中提到的问题发生了,但是,当有结果时 - 它工作得很好。

我已经重写了我的存储过程和用户Select Count()​​来确定我是否应该尝试运行复杂的 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
于 2013-10-02T14:25:29.737 回答
0

我会写作为答案,因为我需要空间

也许您进行查询的框架/类$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中没有大师

于 2013-10-02T13:39:42.173 回答
0

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

于 2013-10-02T13:42:41.910 回答