Android Question I need help to make a php file using MySQLi commands

Espinosa4

Active Member
Licensed User
Longtime User
Hello everyone.


I moved my database from the a site to a new one. Now I have one error when I am trying to connect with my database.

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in

Can you help me to make a new one please? A conversión?
For me is very complicated. I am little by little learning things but still need a lot of help. I looked for info in our forum but I couldn't find anything.

Thank you very much indeed!
PHP:
<?
$databasehost = "host";
$databasename = "db";
$databaseusername = "user";
$databasepassword = "pass";
$con = mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
mysql_select_db($databasename) or die(mysql_error());
mysql_query("SET CHARACTER SET utf8");
$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);
}
?>
 

Espinosa4

Active Member
Licensed User
Longtime User
Ummmm I am still looking info around the world but no results at the moment it is for that reason I wrote here my question.

Many thanks for your help and advises. Very appreciated for me.
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
It's all about:

- adding an i to the commands: mysql_query -> mysqli_query
- adding the connection (e.g. "$con" to the command:

$con = mysqli_connect($host,$user,$pw) or die(mysqli_error());
mysqli_select_db($con,$db) or die(mysqli_error());
mysqli_query($con,"SET CHARACTER SET utf8");
mysqli_query($con,"SET NAMES 'utf8'");


B4X:
<?
$databasehost = "host";
$databasename = "db";
$databaseusername = "user";
$databasepassword = "pass";
$con = mysqli_connect($databasehost,$databaseusername,$databasepassword) or die(mysqli_error());
mysqli_select_db($con, $databasename) or die(mysqli_error());
mysqli_query($con, "SET CHARACTER SET utf8");
$query = file_get_contents("php://input");
$sth = mysqli_query($con, $query);
if (mysql_errno()) {
    header("HTTP/1.1 500 Internal Server Error");
    echo $query.'\n';
    echo mysqli_error();
}
else
{
    $rows = array();
    while($r = mysqli_fetch_assoc($con, $sth)) {
        $rows[] = $r;
    }
    print json_encode($rows);
}
?>
 
Upvote 0

Espinosa4

Active Member
Licensed User
Longtime User


Hi KMatle!
Many many thanks for your reply. I am still learning and I need to see examples to understand how it works.

Thank you very much indeed!
Best regards

PS I tried to add the i but some commands give me some parameters error (numbers). Still learning sorry.
 
Upvote 0

Espinosa4

Active Member
Licensed User
Longtime User
Sure. Ive just read something from there and it is very interesting. I am learning basically seeing example but sometimes I can't fine the exactly thing I need. But... With your advices (thanks to you all for expending your time with us) little by little we have more knowledge.

Thanks
 
Upvote 0

Espinosa4

Active Member
Licensed User
Longtime User
qqq
Yep. As Manfred said it's good to browse for examples. An excellent site is: http://www.w3schools.com/php/php_examples.asp
Hi again KMatle

Can you help one more time please?

The php return this warning
Warning: mysqli_query(): Empty query in /home/u703357939/public_html/linea4vlc.php on line 12

Warning: mysqli_fetch_assoc() expects exactly 1 parameter, 2 given in /home/u703357939/public_html/linea4vlc.php on line 21

I am study the functioin mysqli_fetch_assoc()

I retouched the line like this...
while($r = mysqli_fetch_assoc($sth)) {

but nothing happen.
I am blind in this area. Sorry
Thank you!!!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…