最奇怪的事情刚刚发生:
这是我在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 Query界面中用于测试它 - 并且它没有选择任何表示没有找到表的地方:
这是我的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代码运行脚本时,我什么也得不回来......
答案 0 :(得分: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
答案 1 :(得分: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中没有大师
答案 2 :(得分:0)
我遇到过类似的问题。我猜这是由于分隔符的问题。尝试使用原始的mysql控制台而不是phpMyadmin创建存储过程。