`
zxyskycn
  • 浏览: 50968 次
  • 性别: Icon_minigender_1
  • 来自: 天津
最近访客 更多访客>>
社区版块
存档分类
最新评论

conn

    博客分类:
  • Php
阅读更多
<?php header("Content-Type: text/html; charset=utf-8"); ?>
<?php
class Conn{
	private $host;
	private $user;
	private $pass;
	private $conn;
	private $list=array();
	function __construct($host,$user,$pass){
		$this->host=$host;
		$this->user=$user;
		$this->pass=$pass;
		$this->connect();
	}
	private function connect(){
		$this->conn=mysql_connect($this->host,$this->user,$this->pass) or die("连接数据库服务器失败!");
		mysql_query("set character set utf8")
	}
	function close(){
		mysql_close();
	}
	function openDb($db){
		return mysql_select_db($db) or die("打开数据库失败!");
	}
	function createTab($sql){
		return mysql_query($sql);
	}
	function insert($sql){
		return mysql_query($sql) or die("插入数据失败!".mysql_errno().":".mysql_error());
	}
	function update($sql){
		return mysql_query($sql) or die("更新数据失败!".mysql_errno().":".mysql_error());
	}
	function delete($sql){
		return mysql_query($sql) or die("删除数据失败!".mysql_errno().":".mysql_error());
	}
	function select($sql){
		$result=mysql_query($sql);
		while($row=mysql_fetch_row($result)){
			array_push($this->list,$row);
		}
		return $this->list;
	}
}

$conn=new Conn("127.0.0.1","root","root");
$conn->openDb("mysql");
$create="create table guestbook(id int(11),name varchar(40))";
//$conn->createTab($create);
// for($i=0; $i<5; $i++){
// $insert="insert into guestbook(id,name) values($i,'zxy')";
// $conn->insert($insert);
// }
$update="update guestbook set id=i,name='zxy' where id=2";
//$conn->update($update);
$delete="delete from guestbook where id=1";
//$conn->delete($delete);
$select="select * from guestbook";
$list=$conn->select($select);
//var_dump( $list );
for($i=0; $i<count($list); $i++){
	for($j=0; $j<count($list[$i]); $j++){
		echo $list[$i][$j];
	}
	echo "<br/>";
}

?>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics