Android Question mysqli_query(): Empty query in....

Marco Maria Vilucchi

Active Member
Licensed User
Longtime User
Hi all,
I've been using mysql with b4a for a long time and I've never had problems like this.

From my app I point to a connectdbxandroid posed on mywebsite1 and I get the error: Empty query

If I move the connectdbxandroid to the mywebsite2 web area and change my app to point to that, everything works.

Same DB, same App.
PHP version is 5.6 (both)

I add code.

CONNECTDBXANDROID
Code:
<?php
session_start();// come sempre prima cosa, aprire la sessione

 $client = "xxxxxx";
 $nome = "xxxxxx";
 $password4 = "xxxxxx";
 $directory = "xxxxxx";
 $tabellad = "xxxxxx";
 
date_default_timezone_set('Europe/Rome');

$connessione=mysqli_connect($client,$nome,$password4,$directory);
if (!$connessione) {
  echo('Errore di connessione: ' . mysqli_error());
}
mysqli_set_charset ($connessione , "utf8");
$query = file_get_contents("php://input");
$sth = mysqli_query($connessione, $query);

if (mysqli_errno($connessione)) {
   header("HTTP/1.1 500 Internal Server Error");
   echo $query.'\n';
   echo mysqli_error($connessione);
}
else
{
   $rows = array();
   while($r = mysqli_fetch_assoc($sth)) {
     $rows[] = $r;
   }
   $res = json_encode($rows);
    echo $res;
    mysqli_free_result($sth);
}
mysqli_close($connessione);

?>

QUERY
Code:
'    Send a POST request
    Dim jobx As HttpJob
    Main.Qry="Select * FROM pr11azienda"
    Msgbox2("QRY: " & Main.Qry,"BBBooking","OK","","",LoadBitmap(File.DirAssets,Main.MsgLogo))
    jobx.Initialize("Job0", Me)
    jobx.PostString(Main.ServerUrl, Main.Qry)

J

JOBDONE
Code:
Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
    If Job.Success = True Then
        Select Job.JobName
            Case "Job0"
                Dim parser As JSONParser
                Dim response As String
                response = Job.GetString
                Log(response)
                parser.Initialize(response)
                rows = parser.NextArray
                If rows.size > 0 Then
'                    Msgbox("Risultato 0: " &rows,"")
                    Dim m As Map
'                    Msgbox("rows.size " & rows.size,"")
                    m = rows.Get(0)
                    Main.pr11nome = m.Get("pr11nome")
                    Main.pr11indirizzo = m.Get("pr11indirizzo")
                    messaggio = "pr11nome=" & Main.pr11nome
                    Msgbox2(messaggio,"BBBooking","OK","","",LoadBitmap(File.DirAssets,Main.MsgLogo))
                    Log("Messaggio: " & messaggio)
                Else
                    Main.Accesso="no"
                    messaggio="Utente errato: Accesso non autorizzato"
                    Msgbox2("Messaggio: " & messaggio,"BBBooking","OK","","",LoadBitmap(File.DirAssets,Main.MsgLogo))
                End If

        Case "Job1a"
         ............
         ............
         ............

ERROR
Code:
** Activity (bbnomistanze) Resume **
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
JobName = Job0, Success = true
array(0) {
}
<br />
<b>Warning</b>:  mysqli_query(): Empty query in <b>/web/htdocs/www.preludiocapri.info/home/preludio/prconnectdbxandroid.php</b> on line <b>26</b><br />
<br />
<b>Warning</b>:  mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in <b>/web/htdocs/www.preludiocapri.info/home/preludio/prconnectdbxandroid.php</b> on line <b>36</b><br />
[]<br />
<b>Warning</b>:  mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given in <b>/web/htdocs/www.preludiocapri.info/home/preludio/prconnectdbxandroid.php</b> on line <b>41</b><br />
bbnomistanze_jobdone (java line: 797)
java.lang.RuntimeException: JSON Array expected.
    at anywheresoftware.b4a.objects.collections.JSONParser.NextArray(JSONParser.java:62)
    at com.mamavi.bbbooking.bbnomistanze._jobdone(bbnomistanze.java:797)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1179)
    at android.os.Handler.handleCallback(Handler.java:790)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:7000)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
java.lang.RuntimeException: JSON Array expected.
** Activity (bbnomistanze) Pause, UserClosed = false **

I don't understand why it appens
Thanks for support
Marcom
 
post your php.ini

It may reveal more info about what happens.. I guess server b have another php.ini configuration.
Especially it is this line which can fail on some servers when it is deactivated in the ini.
file_get_contents("php://input");

That said it is probably better to use POST Requests and fetch the query from the Postfield.
 
Upvote 0
Upvote 0
1. There is an error in your PHP
2. the http link is redirected to https. Calling the http link from b4a will raise an empty php://input

http://www.preludiocapri.info/preludio/prconnectdbxandroid.php
Host: www.preludiocapri.info

User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: de,en-US;q=0.7,en;q=0.3

Accept-Encoding: gzip, deflate

DNT: 1

Connection: keep-alive

Upgrade-Insecure-Requests: 1


GET: HTTP/1.1 301 Moved Permanently
Server: aruba-proxy

Date: Mon, 11 Nov 2019 16:11:32 GMT

Content-Type: text/html

Content-Length: 184

Connection: keep-alive

Location: https://www.preludiocapri.info/preludio/prconnectdbxandroid.php

X-ServerName: ipvsproxy107.ad.aruba.it

PUT off forwarding or directly call the correct url.

Also make sure you do not have any redirecting in your .htaccess file.

More i can not help sorry.
 
Upvote 0
Back
Top