I have a mission critical install of EE 1.4.0 (yes, it is that old) that cannot be upgraded (long reasons).
I am trying to fix the error message since our hosting service upgrade to PHP 5.3 (PHP 5.2 no longer supported):
Deprecated: Function mysql_list_tables() is deprecated in…. /db/db.mysql.php on line 406
Here is the offending code:
function fetch_tables()
{
if ( ! $this->conn_id)
{
if ( ! $this->db_connect(0))
{
exit("Database Error: Unable to connect to your database. Your database appears to be turned off or the database connection settings in your config file are not correct. Please contact your hosting provider if the problem persists.");
}
if ( ! $this->select_db())
{
exit("Database Error: Unable to select your database");
}
}
$tables = mysql_list_tables($this->database);
$results = mysql_numrows($tables);
$rows = array();
$i = 0;
while ($i < $results)
{
$row = mysql_tablename($tables, $i);
// if (ereg("^$this->prefix", $row))
if (preg_match("@^$this->prefix@", $row))
{
$rows[] = $row;
}
$i++;
}
return $rows;
}
function table_exists($table_name)
{
if (substr($table_name, 0, 4) == 'exp_')
{
$table_name = substr($table_name, 4);
}
if ( ! in_array($this->prefix.$table_name, $this->fetch_tables()))
{
return FALSE;
}
return TRUE;
}
Using a code sample from EE 1.6.7, I tried to replace it with:
var $tables_list = array();
function fetch_tables()
{
if (sizeof($this->tables_list) > 0)
{
return $this->tables_list;
}
if ( ! $this->conn_id)
{
if ( ! $this->db_connect(0))
{
exit("Database Error: Unable to connect to your database. Your database appears to be turned off or the database connection settings in your config file are not correct. Please contact your hosting provider if the problem persists.");
}
if ( ! $this->select_db())
{
exit("Database Error: Unable to select your database");
}
}
// mysql_list_tables() was depreciated, so we switched to using
// this query, which should work. -Paul
$query = $this->query("SHOW TABLES FROM `{$this->database}` LIKE '{$this->exp_prefix}%'"); // We use $this->exp_prefix as query() will convert it
if ($query->num_rows > 0)
{
foreach($query->result as $row)
{
$this->tables_list[] = array_shift($row);
}
}
return $this->tables_list;
}
function table_exists($table_name)
{
if ($this->prefix != $this->exp_prefix)
{
$table_name = preg_replace("/".$this->exp_prefix."(\S+?)/", $this->prefix."\\1", $table_name);
}
if ( ! in_array($table_name, $this->fetch_tables()))
{
return FALSE;
}
return TRUE;
}
After the code change, the error disappeared, but then I lost ALL theme formatting of the site (it is displaying the site as if it is using the “no style” option in a web browser).
I have no experience with coding, and I am desperately trying to figure out what is wrong and fix it by borrowing examples.
Can someone please help me? I am at a complete lost!