Heroku PHP Refuses more than one query

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I've setup my index.PHP file in Heroku to query the database four (4) disti
nct times and two (2) update queries during the authenticateUser action. Ho
wever, from the XML result, it appears that only the first query is complet
ed and then the remainder are ignored thus creating a truncated XML result  
and without even the closing </data> tag.

I believe Heroku is able handle this action as it is not too complex and wo
rked with XAMPP on my local computer and Google Compute Engine without any  
modifications required. The error log simply notes SET: not found without r
eporting a line

Why would Heroku only allow the completion of the first query, then termina
te the remainder of the action?

How can I make this work?

index.PHP file (authenticateUser action):

case "authenticateUser":
// and return friends and messages

    if ($userId = authenticateUser($db, $username, $password))  

        // providerId and requestId is Id of  a friend pair,
        // providerId is the Id of making first friend request
        // requestId is the Id of the friend approved the friend request ma
de by providerId

        // fetching friends,  
        // left join expression is a bit different,  
        //      it is required to fetch the friend, not the users itself

        $sqlFriends = "select u.Id, u.username, (NOW()-u.authenticationTi
me) as authenticateTimeDifference, u.IP,  
                                    f.providerId, f.requestId, f.status, u.
                        from friends f
                        left join users u on  
                                    u.Id = if ( f.providerId = ".$userI
d.", f.requestId, f.providerId )  
                        where (f.providerId = ".$userId." and f.status=
".USER_APPROVED.")  or  
                                     f.requestId = ".$userId." ";

        //$sqlmessage = "SELECT * FROM `messages` WHERE `touid` = ".$us
erId." AND `read` = 0 LIMIT 0, 30 ";

        $sqlIndMessage = "SELECT m.id, m.fromuid, m.touid, m.sentdt, m.re
ad, m.readdt, m.messagetext, u.username, m.shared_campaign_id, m.shared_cam
paign_location_id from messages m \n"
. "left join users u on u.Id = m.fromuid WHERE `touid` = ".$userId." AN
D `read` = 0 LIMIT 0, 30 ";

        // Queries for selecting groups and group chats
        // Selecting list of groups
        $sqlGroups = "SELECT groupId, groupName  
                      FROM users_groups  
                      WHERE usersId = ".$userId." ";

        // Get group messages related to that users group, note: even if di
dn't send any messages as all
        // will need all messages related to that group and the user name o
f the user sending them
        // finally: even if not a friend of a group memeber, can still get  
the messages they send

        $sqlGroupMessages = "SELECT gm.id, usr.username as 'fromUser', gm
.fromUId, gm.toGroupId, gm.sentdt, gm.read, gm.readdt, gm.messageText  
                             FROM group_messages gm  
                             left join users usr on gm.fromUId = usr.Id
                             WHERE gm.toGroupId IN (SELECT groupId  
                                                    FROM users_groups
                                                    WHERE usersId = ".$us
erId.") AND `read` = 0 LIMIT 0, 30";

        // Because if not in the group/no messages sent to them , should be
        $sqlGroupMessages = "SELECT id, myId, fromUser, fromUId, toGroupN
ame, toGroupId,  sentdt,  `read`,  readdt,  messageText, shared_campaign_id
, shared_campaign_location_id  
                 FROM group_messages  
                 WHERE myId = ".$userId." AND `read` = 0 LIMIT 0, 30";

        // Test setting the textsize to a large number:
        $txtSize = "SET TEXTSIZE 3000";

        if ($result = $db->query($sqlFriends))          
            $out .= "<data>";  
            $out .= "<user userKey='".$userId."' />";
            while ($row = $result->fetch_object())
                $status = "offline";
                if (((int)$row->status) == USER_UNAPPROVED)
                    $status = "unApproved";
                else if (((int)$row->authenticateTimeDifference) < TIME_INT
                    $status = "online";

                $out .= "<friend  username = '".$row->username."'  stat
us='".$status."' IP='".$row->IP."' userKey = '".$row->Id."'  port='

                                        // to increase security, we need to
 change userKey periodically and pay more attention
                                        // receiving message and sending me

            }   // Getting the individual messages
                if ($resultmessage = $db->query($sqlIndMessage))          
                    while ($rowmessage = $resultmessage->fetch_object())
                    $out .= "<message  from='".$rowmessage->username."'
  sendt='".$rowmessage->sentdt."' text='".$rowmessage->messagetext."' s
hared_campaign_id='".$rowmessage->shared_campaign_id."' shared_campaign_l
ocation_id='".$rowmessage->shared_campaign_location_id."' />";
                    $sqlendmsg = "UPDATE `messages` SET `read` = 1, `re
addt` = '".DATE("Y-m-d H:i")."' WHERE `messages`.`id` = ".$rowmessage->

                // Get the groups
                if ($resultGroup = $db->query($sqlGroups))  
                    while ($rowGroup = $resultGroup->fetch_object())
                        $out .= "<groups groupName = '".$rowGroup->grou
pName."' groupId = '".$rowGroup->groupId."' />";

                    // Get Group messages
                    if ($resultGroupMessage = $db->query($sqlGroupMessage
                        while ($rowGroupMessage = $resultGroupMessage->fe
                            $out .= "<group_message fromUser='".$rowGro
upMessage->fromUser."' fromUId='".$rowGroupMessage->fromUId."' toGroupNam
e = '".$rowGroupMessage->toGroupName."' toGroupId = '".$rowGroupMessage
                                    sentdt = '".$rowGroupMessage->sentdt.
"' messageText='".$rowGroupMessage->messageText."' shared_campaign_id='
".$rowGroupMessage->shared_campaign_id."' shared_campaign_location_id='".
$rowGroupMessage->shared_campaign_location_id."' />";
                            $sqlGroupEndMsg = "UPDATE `group_messages` SE
T `read` = 1, `readdt` = NOW() WHERE `group_messages`.`id` = ".$rowGr

                    error_log($out, 0);
                    $out .= "</data>";


            error_log($out, 0);
            $out = FAILED;
            // exit application if not authenticated user
            error_log($out, 0);
            $out = FAILED;


Re: Heroku PHP Refuses more than one query

On 3/15/2015 1:00 AM, k.j.akah08@gmail.com wrote:
Quoted text here. Click to load it

<snip code>

It's hard telling.  I doubt anyone here uses Heroku, and most of us
haven't even heard of it.  Your best bet is to ask Heroku support; they
know their product better than anyone else.  We also don't have your
database, so have no idea if your SQL is correct or not.

However, some suggestions.  Your symptoms generally indicate a fatal
runtime error in your code.  Your "SET: not found" is not a PHP message,
but could indicate a problem with your database.  Since it works on your
local computer but not another one, I would suggest you look for
differences in the systems, especially your database.

Also: On your production system I recommend you have the following in
your php.ini file:

error_log=(absolute path/filename to a log file)

This will also log errors to the indicated file, but not display them.

Note you must restart your webserver after making these changes.

Hopefully this will help you locate your problem.

If you don't have access to the php.ini file and are running Apache, you
can also set these in your .htaccess file.

P.S.  Please don't multipost.  If you must post to multiple newsgroups,
please crosspost.

Remove the "x" from my email address
Jerry Stuckle

Site Timeline