Android Question [Solved] PHP-Script not working anymore

D

Deleted member 103

Guest
Hi,

can someone tell me why my script stops working? It worked fine until a few days ago at 1&1.
Now I only get the error "Internal Server Error".

B4X:
<?php
// Anfang
include("cnf/var.php");
// Ende

$con = mysql_connect($dbhost,$dbusername,$dbpassword) or die(mysql_error());
mysql_select_db($dbname) 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
{
    if (isset($_GET["select"]))
    {
        $rows = array();
        while($r = mysql_fetch_assoc($sth))
        {
            $rows[] = $r;
        }
        print json_encode($rows);
    }
    elseif (isset($_GET["insert"]))
    {
        print mysql_insert_id();
    }
    else
    {
        print $sth;
    }
}
?>
 

OliverA

Expert
Licensed User
You're throwing an internal server error message if you have connection issues with MySQL. Is this causing the issue (your DB down?)?
 
Upvote 0
D

Deleted member 103

Guest
You're throwing an internal server error message if you have connection issues with MySQL. Is this causing the issue (your DB down?)?
No, 1&1 just changed the PHP version from 5.5 to 7.2, and now my script stops working. :(
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
mysql_connect and the others (old connection tools) are not working in PHP5.6+

You need to switch to a MySQLi Class!

The Attached Class comes from here.

PD: Honestly; the deprecation of the old Mysql-Classes is about (at least) FIVE years old!
Check this SO-Answer from 2012.
The fault is yours (you did not updated your php routines for years).
 

Attachments

  • phpMySQLi-Class.zip
    19.3 KB · Views: 241
Last edited:
Upvote 0
D

Deleted member 103

Guest
mysql_connect and the others (old connection tools) are not working in PHP5.6+

You need to switch to a MySQLi Class!

PD: Honestly; the deprecation of the old Mysql-Classes is about 2 years old. The fault is yours (you did not updated your php routines).
Thank you Manfred, but it is not too complicated for me.
Is there any way to convert my script to PHP 7+ ?
 
Upvote 0
D

Deleted member 103

Guest
The fault is yours (you did not updated your php routines for years).
I know, that's my mistake.
I do not know PHP at all.
I put the script together years ago with the help of B4x.
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
No big change. Just change it like that

B4X:
$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'");

Instead

B4X:
mysql_connect

it's

B4X:
mysqli_connect

Mostly they added an i :) Very easy...
 
Upvote 0
D

Deleted member 103

Guest
No big change. Just change it like that

B4X:
$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'");

Instead

B4X:
mysql_connect

it's

B4X:
mysqli_connect

Mostly they added an i :) Very easy...
Unfortunately that is not enough, it comes this error message but no more data.
There's something wrong in the code down here.
B4X:
else
{
    if (isset($_GET["select"]))
    {
        $rows = array();
        while($r = mysqli_fetch_assoc($sth))
        {
            $rows[] = $r;
        }
        print json_encode($rows);
    }
    elseif (isset($_GET["insert"]))
    {
        print mysqli_insert_id();
    }
    else
    {
        print $sth;
    }
}
 
Upvote 0
D

Deleted member 103

Guest
I found it, that's how it works. :)
B4X:
<?php
// Anfang
include("cnf/var.php");
// Ende

$conn = new mysqli($dbhost,$dbusername,$dbpassword,$dbname);
$query = file_get_contents("php://input");

if (mysqli_errno()) {
    header("HTTP/1.1 500 Internal Server Error");
    echo $query.'\n';
    echo mysqli_error();
}
else
{
    $result = $conn->query($query);

    if (isset($_GET["select"]))
    {
        $rows = array();
        while($r = $result->fetch_assoc()) {
            $rows[] = $r;
        }
        print json_encode($rows);
    }
    elseif (isset($_GET["insert"]))
    {
        print $conn->insert_id;
    }
    else
    {
        print $sth;
    }
}
?>
 
Upvote 0
Top