menu

Questions & Answers

PHP Fatal error: Uncaught Error: Call to undefined function mysql_query() - php 7.4

It's OLD PHP script. Could you please fix it for php 7.4 ot 8.1 I don't have that much knowledge.

Help me to fix it.

\\

//Connect to DataBase
function dbconnect($db_host, $db_user, $db_pass, $db_name) {
$db_connect = mysql_connect($db_host, $db_user, $db_pass);
$db_select = mysql_select_db($db_name);
if (!$db_connect) {
die("Error connect to MySQL
".mysql_errno()." : ".mysql_error()."");
} elseif (!$db_select) {
die("Error grab base MySQL
".mysql_errno()." : ".mysql_error()."");
}
}

function dbquery($query)
    {
    $result = @mysql_query($query);
    if (!$result) {
    echo mysql_error();
    return false;
    }
    else
        {
        return $result;
        }
    }

function dbarray($query) {
$result = @mysql_fetch_assoc($query);
if (!$result) {
echo mysql_error();
return false;
} else {
return $result;
}
}
mysql_query('SET NAMES UTF8');
$result = dbquery("SELECT UID, VID, title, addtime, thumb FROM video ORDER BY addtime DESC LIMIT 20");

The error I got this when I run this on php 8.1 -

PHP Fatal error: Uncaught Error: Call to undefined function mysql_query() Stack trace: #0 {main}

please check

Comments:
2023-01-20 23:01:20
mysql_* functions are deprecated as of PHP 5.5.0, and removed as of PHP 7.0.0. Switch your code to use PDO or mysqli instead. Be sure to use prepared statements and parameter binding, so you'll never have to worry about quoting issues again.
2023-01-20 23:01:20
Just FYI, you could have just googled the error and found the cause far more quickly than by posting here
Answers(0) :