0

I am using the following function to read data from database. It's working well in php v5.5 in my local pc. But when I uploaded this code into a server running php v5.3, it's not working.

  function sql_select_many($sql, $db_connection) {
    $mysql_query = mysql_query($sql, $db_connection);
    if ($mysql_query){
        $quantity = mysql_num_rows($mysql_query);
        $return_result = array();
        if($quantity>0){
            $rows = array();
            while ($row = mysql_fetch_assoc($mysql_query)) {
                $rows[] = $row;
            }
            $return_result = array("success"=> true,'count' => $quantity, 'rows'=> $rows);
            mysql_free_result($mysql_query);
        }
        else{
            $return_result = array("success"=> true,'count' => $quantity);
        }
    }
    else{
        $mysql_error = mysql_error($db_connection);
        $error_description = "Failed to execute the following SQL statement: $sql. mysql_error(): $mysql_error";

        $return_result = array("success"=> false);
    }        
    return $return_result ;
}

I'm using the above function here-

$post_categories = sql_select_many("SELECT * FROM `post_categories` where is_active=1", $connection)["rows"];

Can anybody help me to identify the statement/s which are imcompatible with php v5.3

UPDATE- I'm not getting any specific error. When I run the script, it only shows "The page is not working".

s.k.paul
  • 7,099
  • 28
  • 93
  • 168

2 Answers2

0

Most improvements in PHP 5.5.x have no impact on existing code. There are a few incompatibilities.

Upgrade from 5.3 -> 5.4 has more changes which you can find from here: https://www.php.net/manual/en/migration54.incompatible.php

It would also make our work much easier, if you would post the actual errors that you get. "It's not working" is not very well described problem.

Antti A
  • 410
  • 4
  • 12
  • I've updated the question regarding the error message I'm getting. – s.k.paul Sep 30 '19 at 15:35
  • The quickest way to display all php errors and warnings is to add these lines to top of your PHP code file: ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); – Antti A Sep 30 '19 at 15:38
  • Also check https://stackoverflow.com/questions/845021/how-can-i-get-useful-error-messages-in-php – Antti A Sep 30 '19 at 15:40
  • I already have ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); in my script. – s.k.paul Sep 30 '19 at 15:51
  • Next option is to check your webserver logs. There should be something there. If I would guess, I would say the problem is here: `....FROM \`post_categories\` where...` try `...FROM post_categories where...` – Antti A Sep 30 '19 at 15:56
0

Problem is in calling of that function. The following changes worked for me-

The following line modified -

$post_categories = sql_select_many("sql statement ", $connection)["rows"];

I removed ["rows"] from end of the line.

New statements are-

$post_categories = sql_select_many("sql statement ", $connection);
$data = $post_categories["rows"];
s.k.paul
  • 7,099
  • 28
  • 93
  • 168