누구든지 소스코드를 가지고 있다면 올려주세요.
木俞
木俞 2018-03-14 10:48:36
0
1
1319

내 코드에서 계속 오류가 발생합니다. 치명적인 오류: null에서 멤버 함수 exec() 호출

木俞
木俞

모든 응답(1)
秋凉

<?php


class db{

private $dbConfig  = [

'db'  => 'mysql',

'호스트'  => 'localhost',

'포트'  => '3306',

'db이름'   =>  '하나',

'사용자'  => '루트',

'비밀번호'  => '1234',//

'문자 집합'  => 'utf'

];


public $insertId  = null;


public $num = 0;

private static $instance  =  null;


private $conn  = null;



비공개 함수 __construct($params){

$this->dbConfig  = array_merge($this->dbConfig,$params);

$this->conncet();

}

비공개 함수 __clone(){


}

공개 함수 getInstance(){

if(!self::$instance instanceof self){

self::$instance   = new self();

}

return self::$instance;

}

공개 함수 connect(){

try{

$dsn  = "{$this->dbConfig['db']}:{$this ->dbConfig['host']};

포트  = {$this->dbConfig['port']};

charset  = {$this->dbConfig['charset']}";

$this->conn  = new pdo($dsn,$this->dbConfig['user'],$this->dbConfig['password']);

}

catch(PDOExecption $e){ ㅋㅋㅋ

// 返回受影响的记录如果New增还返回new增主键id

public function exec($sql){

$num = $this->conn->exec($sql);

// 如果有受影响的记录

if($num>0){

// 如果是new增操作 初始化新增主键ID的属性

if(null !==$this->conn->lastInsertId()){

$this ->insertId = $this->conn->lastInsertId();

}

$this->num = $rum;//返回受影响的记录

}else{

$error = $this->conn->errorInfo(); //获取最后操작품错误信息 【0】错误标识符 【1】错误代码【2】错误信息

print '操작품失败'.$error[0].':'.$error[1].': '.$error[2];

}

}

//获取单条查询信息

공개 함수 가져오기($sql )

{

return $this->conn->query ($sql)->fetch(PDO::FETCH_ASSOC);

}

공개 함수 fetchALL($sql){

return $this->conn->query($sql)->fetch( PDO::FETCH_ASSOC);

}

}

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!