Upgrade sql script from php 5.4 to latest

Viewed 12

Someone help me re-write this script so that it can work on PHP Version 7 and above!

I don't want suggestions, i want answers with the updated script. If you can't respond to my request don't bother... Meanwhile have applied the normal method, got it to login but was unable to fetch data from the database. I really need someone who can help me update this script and get it to work with at least PHP Version 7.0 and above. It can work normally on PHP Version 5.4, 5.5, 5.6 only. We keep having issues of security risk. God Bless

<?php
ini_set('display_errors', 'off');
//ob_start("ob_gzhandler");
//error_reporting(E_ALL);

// start the session
session_start();

// database connection config
$dbHost = 'localhost';
$dbUser = '';
$dbPass = '';
$dbName = '';

//Project data
$site_title = '';
$email_id = '';

// setting up the web root and server root for
// this shopping cart application
$thisFile = str_replace('\\', '/', __FILE__);
$docRoot = $_SERVER['DOCUMENT_ROOT'];

$webRoot  = str_replace(array($docRoot, 'library/config.php'), '', $thisFile);
$srvRoot  = str_replace('library/config.php', '', $thisFile);

define('WEB_ROOT', $webRoot);
define('SRV_ROOT', $srvRoot);

// these are the directories where we will store all
// category and product images
define('USER_IMAGE_DIR', 'images/thumbnails/');

// some size limitation for the category
// and product images

// all category image width must not 
// exceed 75 pixels
define('MAX_USER_IMAGE_WIDTH', 180);

// do we need to limit the product image width?
// setting this value to 'true' is recommended
define('LIMIT_USER_WIDTH',     true);

// the width for product thumbnail
define('THUMBNAIL_WIDTH',      180);

if (!get_magic_quotes_gpc()) {
    if (isset($_POST)) {
        foreach ($_POST as $key => $value) {
            $_POST[$key] =  trim(addslashes($value));
        }
    }
    
    if (isset($_GET)) {
        foreach ($_GET as $key => $value) {
            $_GET[$key] = trim(addslashes($value));
        }
    }
}

require_once 'database.php';

?>

<?php
require_once 'config.php';

$dbConn = mysql_connect ($dbHost, $dbUser, $dbPass) or die ('MySQL connect failed. ' . mysql_error());
mysql_select_db($dbName) or die('Cannot select database. ' . mysql_error());

function dbQuery($sql)
{
    $result = mysql_query($sql) or die(mysql_error());
    return $result;
}

function dbAffectedRows()
{
    global $dbConn;
    return mysql_affected_rows($dbConn);
}

function dbFetchArray($result, $resultType = MYSQL_NUM) {
    return mysql_fetch_array($result, $resultType);
}

function dbFetchAssoc($result)
{
    return mysql_fetch_assoc($result);
}

function dbFetchRow($result) 
{
    return mysql_fetch_row($result);
}

function dbFreeResult($result)
{
    return mysql_free_result($result);
}

function dbNumRows($result)
{
    return mysql_num_rows($result);
}

function dbSelect($dbName)
{
    return mysql_select_db($dbName);
}

function dbInsertId()
{
    return mysql_insert_id();
}
?>

0 Answers
Related