Weirdest thing has just happen:
This is my SP as written in PhpMyAdmin MySql interface:
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
This is how the result using the "Execute" button in the PhpMyAdmin looks like. pay attention to the query the interface has generated:
This is the exact query being copy/paste by me and used in the PhpMyAdmin SQL Query interface in order to test it - and it select nothing saying no tables were found:
This is my call from my php code:
/**
* 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')");
}
Which generates the query:
Call getEventActiveAlbum('10230910','42','613714903')
Any idea why this is happening ? when running the script from PHP code i get nothing back...
i'll write as answer as i need space
maybe your framework/class that makes query $this->queryDb
is using older mysql rather than newer mysqli. for the fun of it, try
$conn = mysqli_connect("hostname", "user", "password", "db", "port");
$result = mysqli_query(
$conn,
"Call getEventActiveAlbum('$eventCode','$eventKey','$facebookId')"
)
or die("failed: " . mysqli_error());
ps no guru in mysql
I have encountered a similar issue like this.I guess it's due to the issue with delimiter. Try to create stored procedure using original mysql console instead of phpMyadmin.
Ok I solved it:
The problem was with the select statement.
When there were no results - the problem mantioned in the this question happened, but, when there were results - it worked fine.
I've rewritten my stored procedure and user the Select Count()
to determine if i should event try to run the complicated select statement, as follow:
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