php - Deprecated: mysql_connect() Error Code -
this question has answer here:
my host upgrade php version , part of website shows following error:
deprecated: mysql_connect(): mysql extension deprecated , removed in future: use mysqli or pdo instead in url/structure/here on line 49
that referencing below code:
function dbconnect() { $this->connectcount ++; //echo "$this->connectcount<br>"; 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 fact because current way site connects mysql outdated in new version of php know how update above code make work?
the easier way use mysqli_connect(). syntax similar had mysql_connect(),which means changes in code minor , easy make.
pdo safest, if trying site on quickly, mysqli_* commands achieve that.
google (or check on stackoverflow) mysql vs mysqli. ll find plenty of examples.
hope helps.
good luck
--
sorry after re-reading see asked needs change on source code. afraid cannot right responding mobile phone :(
Comments
Post a Comment