Search code examples
php-5.3php-5.5

Code not working when migrating from php v5.5 to php v5.3


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".


Solution

  • 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"];