View attachment 70972 View attachment 70972 I have a project that retrieve information from database through php codes , but after upgrading to 8.0 b4a i started getting lots off errors or returning null as result or giving java.lang.RuntimeException: JSON array expected. i have done all i could without solution. is their anything i am not doing? help pls . I used example example giving by Kmatle in his tutorial
my php code is
<?
#include ("db.php");
#$host = "localhost";
#$user = "y";
#$pw = "a";
#$db = "tolu";
#$con = mysql_connect($host,$user,$pw) or die(mysql_error());
$con = mysqli_connect("localhost", "y", "a", "tolu");
// Check connection
if($con === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
mysqli_query("SET CHARACTER SET utf8");
$action = $_GET["action"];
switch ($action)
{
case "CountPersons":
# print json_encode("just yap");
$q = mysql_query("SELECT * FROM persons");
$count = mysql_num_rows($q);
print json_encode($count);
break;
Case "GetPersons":
$q = mysql_query("SELECT name, age FROM Persons");
$rows = array();
while($r = mysqli_fetch_assoc($q))
{
$rows[] = $r;
}
print json_encode($rows);
break;
case "InsertNewPerson":
$name = $_GET["name"];
$age = $_GET["age"];
$q = mysqli_query("INSERT INTO Persons (name, age) VALUES ('$name', $age)");
print json_encode("Inserted");
break;
}
?>
my php code is
<?
#include ("db.php");
#$host = "localhost";
#$user = "y";
#$pw = "a";
#$db = "tolu";
#$con = mysql_connect($host,$user,$pw) or die(mysql_error());
$con = mysqli_connect("localhost", "y", "a", "tolu");
// Check connection
if($con === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
mysqli_query("SET CHARACTER SET utf8");
$action = $_GET["action"];
switch ($action)
{
case "CountPersons":
# print json_encode("just yap");
$q = mysql_query("SELECT * FROM persons");
$count = mysql_num_rows($q);
print json_encode($count);
break;
Case "GetPersons":
$q = mysql_query("SELECT name, age FROM Persons");
$rows = array();
while($r = mysqli_fetch_assoc($q))
{
$rows[] = $r;
}
print json_encode($rows);
break;
case "InsertNewPerson":
$name = $_GET["name"];
$age = $_GET["age"];
$q = mysqli_query("INSERT INTO Persons (name, age) VALUES ('$name', $age)");
print json_encode("Inserted");
break;
}
?>