Hello,
If I refer at the tuto https://www.b4x.com/android/forum/threads/connect-android-to-mysql-database-tutorial.8339/ it seems it does not need "sql" library. Isn't it ?
I create on the server, as shown, a php script file, essai.php
Look at my code below, the Buttons-click : I do not find the exact syntax for:
ExecuteRemoteQuery("SELECT * FROM MyTable WHERE champs1 ='" & Val1 & "' ,ESSAI_3)
ExecuteRemoteQuery("SELECT COUNT MyTable ................,ESSAI_4)
Can you help me and indicate the good syntax? I find many samples but they do not run.
Thank you
If I refer at the tuto https://www.b4x.com/android/forum/threads/connect-android-to-mysql-database-tutorial.8339/ it seems it does not need "sql" library. Isn't it ?
I create on the server, as shown, a php script file, essai.php
Look at my code below, the Buttons-click : I do not find the exact syntax for:
ExecuteRemoteQuery("SELECT * FROM MyTable WHERE champs1 ='" & Val1 & "' ,ESSAI_3)
ExecuteRemoteQuery("SELECT COUNT MyTable ................,ESSAI_4)
Can you help me and indicate the good syntax? I find many samples but they do not run.
Thank you
B4X:
Sub ExecuteRemoteQuery(Query As String, JobName As String)
Dim job As HttpJob
job.Initialize(JobName, Me)
job.PostString("https://myTable/applis/essai.php", Query)
End Sub
Sub JobDone(Job As HttpJob)
ProgressDialogHide
If Job.Success Then
Dim res As String
res = Job.GetString
Log("Response from server: " & res)
Dim parser As JSONParser
parser.Initialize(res)
Select Job.JobName
Case ESSAI_1
Dim ESSAI1 As List
ESSAI1 = parser.NextArray 'returns a list with maps
For i = 0 To ESSAI1.Size - 1
Dim m As Map
m = ESSAI1.Get(i)
Dim valeur1, valeur2, valeur3 As string
valeur1 = m.Get("champs1")
valeur2 = m.Get("champs2")
valeur3 = m.Get("champs3")
Log(valeur1 & " " & valeur2 & " " & valeur3)
Next
Case ESSAI_2
MsgboxAsync("It runs fine", "Result")
Case ESSAI_3
Dim ESSAI3 As List
ESSAI3 = parser.NextArray 'returns a list with maps
For i = 0 To ESSAI3.Size - 1
Dim m As Map
m = ESSAI3.Get(i)
Dim valeur1, valeur2, valeur3 As string
valeur1 = m.Get("champs1")
valeur2 = m.Get("champs2")
valeur3 = m.Get("champs3")
Log(valeur1 & " " & valeur2 & " " & valeur3)
Next
Case ESSAI_4
MsgboxAsync("It runs fine", "Result")
End Select
Else
Log(Job.ErrorMessage)
ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub
Sub Button1_Click
'It Runs fine
ExecuteRemoteQuery("SELECT * FROM MyTable WHERE champs1 = 1",ESSAI_1 )
End Sub
Sub Button2_Click
Dim val1, val2, val3 as String
Val1 = "Hello"
val2 = "The"
val3 = "World"
'It Runs fine
ExecuteRemoteQuery("INSERT INTO MyTable (champs1, champs1, champs1) VALUES ('" & Val1 & "', '" & Val2 & "','" & val3')",ESSAI_2)
End Sub
Sub Button3_Click
Dim val1, val2, val3 as String
Val1 = "Hello"
val2 = "The"
val3 = "World"
'Synta error
ExecuteRemoteQuery("SELECT * FROM MyTable WHERE champs1 ='" & Val1 & "' ,ESSAI_3)
'Synta error
ExecuteRemoteQuery("SELECT * FROM MyTable WHERE champs1 ='" & Val1 & "' ,ESSAI_3)
' Here, Erreur, l'objet a été transformé en variable string (Idem if I remplace Array as string by Array as Object)
ExecuteRemoteQuery("SELECT * FROM MyTable where champs1 = ? and champs2 = ?", Array As String (val1, val3), CHECK)
End Sub
Sub Button4_Click
'IWhat is the syntax ?
ExecuteRemoteQuery("SELECT COUNT MyTable ................,ESSAI_4)
End Sub