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

您的位置:首頁技術文章
文章詳情頁

為什么說非對象調用成員函數fetch()

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

問題描述

<?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; ///數據庫的連接 private $conn = null; private function __construct($params) {//初始化參數array_merge($this->dbConfig, $params);//連接數據庫$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']}";//創建pdo對象$this->conn= new PDO($dsn,$this->dbConfig['user'],$this->dbConfig['pass']); //// $this->conn->query("SET NAMES {$this->dbConfig['charset']}");}catch (PDOException $e){ die('數據庫連接失敗'.$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 是錯誤標識符 1 是錯誤代碼 2 是錯誤信息 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);; }}

問題解答

回答1:

pdo對象沒有獲取成功,調用了一個對象成員方法fetch, 檢查連接參數

相關文章:
主站蜘蛛池模板: 漳浦县| 双桥区| 义乌市| 泸西县| 衡东县| 博客| 丹巴县| 屯门区| 额敏县| 唐山市| 阳曲县| 德钦县| 合山市| 横峰县| 登封市| 吉安市| 巨鹿县| 北安市| 四会市| 万荣县| 梁平县| 阳朔县| 凤冈县| 康马县| 滨州市| 吉木萨尔县| 桑日县| 永年县| 靖远县| 三明市| 英山县| 麻江县| 赤峰市| 吕梁市| 威远县| 正定县| 阿图什市| 扎鲁特旗| 兴海县| 临澧县| 东明县|