日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

php7不支持mysql扩展了么_php7不支持mysql扩展需要改成mysqli扩展

發布時間:2024/9/19 数据库 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php7不支持mysql扩展了么_php7不支持mysql扩展需要改成mysqli扩展 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最近升級php7發現不支持mysql擴展,需要改成用mysqli擴展

看代碼class Db{

private $username = '';

private $password = '';

private $host = '';

private $db = '';

private $mysqli_conn;

public function __construct(){

$this->mysqli_conn = @mysqli_connect($this->host,$this->username, $this->password);

if(!$this->mysqli_conn){

die("could not connect to the database:\n".mysqli_error($this->mysqli_conn));

}

mysqli_query($this->mysqli_conn,"set names 'utf8'");//編碼轉化

$select_db = mysqli_select_db($this->mysqli_conn,$this->db);

}

public function query($query){

return mysqli_query($this->mysqli_conn, $query);

}

public function fetch_assoc($result){

return mysqli_fetch_assoc($result);

}

public function fetch_array($result){

return mysqli_fetch_array($result);

}

public function getAll($table,$filed,$where='1=1',$order='',$limit=''){

$array = array();

$sql = "SELECT {$filed} FROM {$table} WHERE {$where} {$order} {$limit}";

$result = $this->query($sql) or die("db.php;Action:getAll;problem:".$sql.mysqli_error($this->mysqli_conn));

while($row = $this->fetch_assoc($result)){

$array[] = $row;

}

return $array;

}

public function getOne($table,$filed,$where='1=1'){

$sql ="SECLECT {$filed} FROM {$table} WHERE {$where} limit 1";

$result = $this->query($sql) or die("db.php;Action:getOne;problem:".$sql.mysqli_error($this->mysqli_conn));

$row = $this->fetch_assoc($result);

return $row;

}

public function getCount($table,$where="1=1"){

$sql ="SELECT COUNT(1) as count FROM {$table} WHERE {$where}";

$result = $this->query($sql) or die("db.php;Action:getCount;".$sql.mysqli_error($this->mysqli_conn));

$row = $this->fetch_array($result);

if(!$row['count']){

$row['count'] = '0';

}

return $row['count'];

}

public function delete($table,$where="1=1"){

$sql ="DELETE FROM {$table} WHERE {$where}";

$result = $this->query($sql) or die("db.php;Action:delete;".$sql.mysqli_error($this->mysqli_conn));

return $result;

}

public function insert($table,array $data){

$data = $this->_dataFormat($data);

$sql = "insert into ".$table."(".implode(',',array_keys($data)).") values (".implode(',',array_values($data)).")";

$result = $this->query($sql) or die("db.php;Action:insert;".$sql.mysqli_error($this->mysqli_conn));

return $result;

}

public function update($table,array $data,$where="1=1") {

$data = $this->_dataFormat($data);

if (!$data) return;

$valArr = '';

foreach($data as $k=>$v){

$valArr[] = $k.'='.$v;

}

$valStr = implode(',', $valArr);

$sql = "update ".$table." set ".trim($valStr)." where {$where}";

$result = $this->query($sql) or die("db.php;Action:update;".$sql.mysqli_error($this->mysqli_conn));

return $result;

}

priavte function _dataFormat($data) {

if (!is_array($data)) return array();

$ret=array();

foreach ($data as $key=>$val) {

if (!is_scalar($val)) continue; //值不是標量則跳過

$key = $this->_addChar($key);

if (is_int($val)) {

$val = intval($val);

} elseif (is_float($val)) {

$val = floatval($val);

} elseif (preg_match('/^\(\w*(\+|\-|\*|\/)?\w*\)$/i', $val)) {

$val = $val;

} elseif (is_string($val)) {

$val = '"'.addslashes($val).'"';

}

$ret[$key] = $val;

}

return $ret;

}

priavte function _addChar($value) {

if ('*'==$value || false!==strpos($value,'(') || false!==strpos($value,'.') || false!==strpos($value,'`')) {

} elseif (false === strpos($value,'`') ) {

$value = '`'.trim($value).'`';

}

return $value;

}

}

主要注意是mysqli_query這個函數兩個參數是必須填寫的,而mysql_query參數與之相反和第二個參數可以不填寫!

總結

以上是生活随笔為你收集整理的php7不支持mysql扩展了么_php7不支持mysql扩展需要改成mysqli扩展的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。