久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

為什么說(shuō)非對(duì)象調(diào)用成員函數(shù)fetch()

瀏覽:163日期:2022-06-03 15:53:52

問(wèn)題描述

<?phpclass Db{ private $dbConfig=['db'=>'mysql','host'=>'localhost','port'=>'3306','user'=>'root','pass'=>'root','charset'=>'utf8','dbname'=>'edu',]; //單例模式 private static $instance = null; public $insertID = null; public $num1 = null; ///數(shù)據(jù)庫(kù)的連接 private $conn = null; private function __construct($params) {//初始化參數(shù)array_merge($this->dbConfig, $params);//連接數(shù)據(jù)庫(kù)$this->connect(); } private function __clone() {// TODO: Implement __clone() method. } public static function getInstance($params=[]) {if(!self::$instance instanceof self){ self::$instance = new self($params);}return self::$instance; } private function connect() {try {$dsn="{$this->dbConfig['db']}:host={$this->dbConfig['host']};port={$this->dbConfig['port']};dbname={$this->dbConfig['dbname']};charset={$this->dbConfig['charset']}";//創(chuàng)建pdo對(duì)象$this->conn= new PDO($dsn,$this->dbConfig['user'],$this->dbConfig['pass']); //// $this->conn->query("SET NAMES {$this->dbConfig['charset']}");}catch (PDOException $e){ die('數(shù)據(jù)庫(kù)連接失敗'.$e->getMessage());} } public function exec($sql) {$num = $this->conn->exec($sql);if($num>0){ if(null !== $this->conn->lastInsertID()) {$this->insertID = $this->conn->lastInsertID(); } $this->num1= $num;}else{ $error = $this->conn->errorInfo(); //0 是錯(cuò)誤標(biāo)識(shí)符 1 是錯(cuò)誤代碼 2 是錯(cuò)誤信息 print '操作失敗'.$error[0].':'.$error[1].':'.$error[2];} } public function fetch($sql) {return $this->conn->query($sql)->fetch(PDO::FETCH_ASSOC); } public function fetchALl($sql) {return $this->conn->query($sql)->fetch(PDO::FETCH_ASSOC);; }}

問(wèn)題解答

回答1:

pdo對(duì)象沒(méi)有獲取成功,調(diào)用了一個(gè)對(duì)象成員方法fetch, 檢查連接參數(shù)

相關(guān)文章:
主站蜘蛛池模板: 梧州市| 武胜县| 二连浩特市| 长垣县| 卢湾区| 霍城县| 渑池县| 泌阳县| 新蔡县| 建始县| 乡宁县| 三亚市| 三门峡市| 凤台县| 察哈| 来宾市| 闻喜县| 荣成市| 鄂伦春自治旗| 余江县| 封丘县| 德兴市| 修武县| 九寨沟县| 桑日县| 合川市| 赤峰市| 罗定市| 乌兰浩特市| 金寨县| 濉溪县| 湖南省| 行唐县| 漳平市| 澄迈县| 河池市| 子洲县| 永胜县| 芜湖市| 理塘县| 府谷县|