Sunday, 10 July 2016

php - Deprecated: mysql_connect() Error Code

My host recently upgrade the PHP version and a certain part of my website now shows the following error:




Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in url/structure/here on line 49


That is referencing the below code:



function DBConnect() {  
$this->connectCount ++;
//echo "$this->connectCount
";


if ($this->dbType == 'mysql') {
$dbConnect = mysql_connect($this->dbHost, $this->dbUser, $this->dbPasswd) or die ("MySql Connection Failed: " . mysql_error());
mysql_select_db($this->dbName, $dbConnect);
}

if ($this->dbType == 'postgresql') {
$dbConnect = pg_connect("host=$this->dbHost port=$this->dbPort dbname=$this->dbName user=$this->dbUser password=$this->dbPasswd") or die ("PostgreSQL Connection Failed: " . pg_errormessage($dbConnect));
//$dbConnect = pg_pconnect("host=$this->dbHost port=$this->dbPort dbname=$this->dbName user=$this->dbUser password=$this->dbPasswd") or die ("PostgreSQL Connection Failed: " . pg_errormessage($dbConnect));
}


return $dbConnect;
}


I'm aware the fact that this is because the current way my site connects to MYSQL is now outdated in the new version of PHP but does anyone know how I would update the above code to make this work?

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...