<?
$databasehost = "127.0.0.1";
$databasename = "nome db";
$databaseusername ="user";
$databasepassword = "pw";
$con = mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
mysql_select_db($databasename) or die(mysql_error());
$query = file_get_contents("php://input");
$sth = mysql_query($query);
if (mysql_errno()) {
header("HTTP/1.1 500 Internal Server Error");
echo $query.'\n';
echo mysql_error();
}
else
{
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
$rows[] = $r;
}
print json_encode($rows);
}
?>
Sub Process_Globals
Dim hc As HttpClient
Dim TaskID_SUB As Int
TaskID_SUB = 1
End Sub
Sub Globals
Dim ListView1 As ListView
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("test")
If FirstTime Then
hc.Initialize("hc")
End If
End Sub
Sub Seleziona_da_tab1
ProgressDialogShow("Select da tabella TAB1")
ExecuteRemoteQuery("SELECT * FROM TAB1", 1)
End Sub
Sub ExecuteRemoteQuery(Query As String, TaskID As Int)
' connessione al db mysql
Dim req As HttpRequest
req.InitializePost2("http://127.0.0.1:8080/MOBILE/Conn.php", Query.GetBytes("UTF8"))
hc.Execute(req, TaskID)
End Sub
Sub hc_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskID As Int)
Log("Risposta Errore server: " & Reason & ", Codice stato: " & StatusCode)
If Response <> Null Then
Log(Response.GetString("UTF8"))
Response.Release
End If
ProgressDialogHide
End Sub
Sub hc_ResponseSuccess (Response As HttpResponse, TaskID As Int)
Dim res As String
res = Response.GetString("UTF8")
Log("Response from server: " & res)
Dim parser As JSONParser
parser.Initialize(res)
Select TaskID
Case TaskID_SUB
'add the countries to the ListView
Dim cmdslc As List
cmdslc = parser.NextArray 'returns a list with maps
For i = 0 To cmdslc.Size - 1
Dim m As Map
m = cmdslc.get(i)
'We are using a custom type named TwoLines (declared in Sub Globals).
'It allows us to later get the two values when the user presses on an item.
Dim getline As String
getline = m.get("DESC")
ListView1.AddSingleLine(m)
Next
ProgressDialogHide
End Select
Response.Release
End Sub
$query = file_get_contents("php://input");
$query = $_GET['input'];
echo $query ;
Sub ExecuteRemoteQuery(Query As String, TaskID As Int)
' connessione al db mysql
Dim req As HttpRequest
Dim stringa As String
req.InitializePost2("http://127.0.0.1:8080/MOBILE/Conn.php", Query.GetBytes("UTF8"))
hc.Execute(req, TaskID)
stringa = req
Msgbox(stringa, "")
End Sub
Ciao Luigi
Ho risolto tutto!
Ora mi collego tranquillamente al mio db mysql, ho testato anche la connessione al database su un mysql remto installato su un mio dominio e funziona benissimo!!
Grazie per le dritte su php!!
Ciao:sign0060::sign0060::sign0060:
B4X:Sub ExecuteRemoteQuery(Query As String, TaskID As Int) ' connessione al db mysql Dim req As HttpRequest Dim stringa As String req.InitializePost2("http://127.0.0.1:8080/MOBILE/Conn.php", Query.GetBytes("UTF8")) hc.Execute(req, TaskID) stringa = req Msgbox(stringa, "") End Sub
<?php //definisco i parametri della connessione: nomeserver,username,password e nome db
$databasehost = "127.0.0.1";
$databasename = "mydb"; //con una sola table cliente
$databaseusername ="root";
$databasepassword = "";
$con = mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
mysql_select_db($databasename, $con) or die(mysql_error());
mysql_query("SET CHARACTER SET utf8");
//$query = file_get_contents("php://input");
$query = $_GET['input'];
echo $query;
$sth = mysql_query($query);
if (mysql_errno()) {
header("HTTP/1.1 500 Internal Server Error");
echo $query.'\n';
echo mysql_error();
}
else
{
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
$rows[] = $r;
}
print json_encode($rows);
}
mysql_close($con);
?>
http://localhost/connect.php?input="select * f_rom cliente"
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?