Android Question [Solved] PHP-Script not working anymore

  • Thread starter Thread starter Deleted member 103
  • Start date Start date
  • Similar Threads Similar Threads Similar Threads
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".

Code:
<?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;
    }
}
?>
 
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
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
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

Last edited:
Upvote 0
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
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
No big change. Just change it like that

Code:
$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

Code:
mysql_connect

it's

Code:
mysqli_connect

Mostly they added an i :-) Very easy...
 
Upvote 0
No big change. Just change it like that

Code:
$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

Code:
mysql_connect

it's

Code:
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.
Code:
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
I found it, that's how it works. :)
Code:
<?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
Back
Top