您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php数据库操作实例

2024/6/5 0:23:02发布25次查看
open($server,$dbuser,$psw); } private function open($server,$dbuser,$psw){//连接主机 $this->host=$server; $this->name=$dbuser; $this->password=$psw; $this->link=mysql_connect($this->host,$this->name,$this->password) or die(主机连接失败!);; } public function to2darray($result){ $_2darray=array(); $arr=new arrayobject($_2darray); while($row=mysql_fetch_array($result)){ $arr->append($row); } return $arr ; } public function opendb($database,$charset){//连接数据库 $this->dbname=$database; mysql_query(set names .$charset);//设置字符集 $this->db=mysql_select_db($this->dbname,$this->link); if (!$this->db) { $this->errmsg=连接数据库错误!; } } public function query($sql) { $result=mysql_query($sql); if (!$result) { $this->errmsg=语句运行错误!; } return $result; } private function __call($n,$v){//错误方法吸收 return 不存在.$n.()方法; }}//example// $c=new mysql(localhost,root,lijun);// $c->opendb(demo, utf8);// $r=$c->query(select * from test);// echo $r,'
';// $ar=$c->to2darray($r);// print_r($ar[0]);// echo '
';// print_r($ar[1]);// echo '
';// echo $c->hi();?>
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product