Rumah  >  Soal Jawab  >  teks badan

Jika sesiapa mempunyai kod sumber, sila siarkan.

Kod saya terus mendapat ralat: Ralat maut: Panggilan ke fungsi ahli exec() pada nol

木俞木俞2383 hari yang lalu1321

membalas semua(1)saya akan balas

  • 秋凉

    秋凉2018-03-14 21:10:44

    <?php


    kelas db{

    peribadi $dbConfig  = [

    'db'  => 'mysql',

    'host'  => 'localhost',

    'port'  => '3306',

    'dbname'   =>  'satu',

    'pengguna'  => 'root',

    'password'  => '1234',//

    'charset'  => 'utf'

    ];


    awam $insertId  = null;


    awam $num = 0;

    peribadi statik $instance  =  null;

     noll;



    fungsi peribadi __construct($params){

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

    ;

    ; $this-config> }

    fungsi peribadi __clone(){


    }

    fungsi awam getInstance(){

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

    self:=$instance baru( ); 

    }

    kembalikan diri::$instance;

    }

    public function connect(){

    try{

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

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

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

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

    }

    catch(PDOExecption $e){

    die("数据库连接失败".$e->getMessage());

    }

    }

    // 完成数据表成数据表的墙除

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

    public function exec($sql){

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

    // 如协果

    jika ($ num & gt; 0) {

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

    if (null! == $ this- & gt; conn- & gt; lastInsertid ()) {

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

    }

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

    }

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

    的记录

    $this->conn->errorInfo(); //获取最后操作的错误信息 【0】错误标识符 【1】错误代码【2】错误信 '息月 cetak ].':'.$error[1].': '.$error[2];

    }

    }


    //获取单条查询信息

    public function fetch ($sql )

    ;pertanyaan ($sql)->fetch(PDO::FETCH_ASSOC);

    }

    public function fetchALL($sql){

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

    }

    }


    balas
    0
  • Batalbalas