Forum Moderators: coopster
// at top of script that's included on every PHP page
if (phpversion() >= 7)
// not sure if I can put a single copy of mysql_functions.php on the server and
// let all of my shared hosting accounts access it? That'd be great; otherwise,
// I'd have a copy in the /public_html/ of each account
require_once '/home/mysql_functions.php';
// mysql_functions.php
function mysql_connect($host, $user, $pass) {
$GLOBALS['dbh'] = @mysqli_connect($host, $user, $pass);
return $GLOBALS['dbh'];
}
function mysql_select_db($db) {
global $dbh;
return mysqli_select_db($dbh, $db);
}
function mysql_query($query) {
global $dbh;
return mysqli_query($dbh, $query);
}
function mysql_real_escape_string($text) {
global $dbh;
return mysqli_real_escape_string($dbh, $text);
}
function mysql_fetch_array($text) {
return mysqli_fetch_array($text);
}
function mysql_fetch_assoc($text) {
return mysqli_fetch_assoc($text);
}
function mysql_fetch_row($text) {
return mysqli_fetch_row($text);
}
function mysql_num_rows($text) {
return mysqli_num_rows($text);
}
// and so on for any other MySQL function I use class Database {
public function query($sql)
{
$result = $this->_db->query($sql);
if (!$result) {
$this->_error($sql); // internal error handler
}
$this->numRows = $this->_db->affected_rows;
return $result;
}
}