<?php //mysql数据库类-mysqli版 //2014/6/13 class mysqlidb{ public $dbhost; public $dbuser; public $dbpasswd; public $dbname; public $dbport; public $dbobject; public function __contruct($host,$user,$pwd,$dbname,$port=3306){ $this->dbhost = $host; $this->dbuser = $user; $this->dbpasswd = $pwd; $this->dbname = $dbname; $this->dbport = $port; $this->dbobject = new mysqli($this->dbhost,$this->dbuser,$this->dbpasswd,$this->dbname,$this->dbport); if ( $this->dbobject -> connect_error ) { die( 'Connect Error (' . $this->dbobject -> connect_errno . ') ' . $this->dbobject -> connect_error ); } } public function executesql($sql,$param=array()){ $dbstmt = $this->dbobject->prepare($sql); if(!empty($param)){ foreach($param as $k => $v){ $dbstmt -> bind_param($k,$v); } } $dbstmt -> execute(); $dbresult = $dbstmt -> get_result(); return $dbresult->fetch_array(); } } $db = new mysqlidb('127.0.0.1','root','','mysql'); $sql = 'select * from User'; $dbrs = $db->executesql($sql); //Fatal error: Call to a member function prepare() on a non-object in C:xampphtdocs ongleimysqlidemo2.php on line 28