<?php
/**
mysql封装类
**/
error_reporting(E_ALL);
class mysql{
private $host;
private $user;
private $pwd;
private $dbName;
private $charset;
private $conn=null;
public function __construct(){
$this->host='localhost';
$this->user='root';
$this->pwd='123456';
$this->dbName='qian';
//连接
$this->connect($this->host,$this->user,$this->pwd);
//切换库
$this->dbSwitch($this->dbName);
//设置字符集
$this->setChar($this->charset);
}
//负责连接
private function connect($h,$u,$p){
$conn=mysql_connect($h,$u,$p);
$this->conn=$conn;
}
//负责切换数据库
public function dbSwitch($db){
$sql='use'.$db;
$this->query($sql);
}
//负责设置字符集
public function setChar($char){
$sql='set names'.$char;
$this->query($sql);
}
//负责发送SQL 查询
public function query($sql){
$sql= mysql_query($sql,$this->conn);
return $sql;
}
//负责获取多行多列的select结果
public function getAll($sql){
}
}
$db=new mysql();
$a='insert into rong (id,name,pwd) values (14,"我的文档","123456")';
$db->query($a);
if($db->query($a)){
echo "输入数据成功";
}else{echo "输入数据失败";}
/**
mysql封装类
**/
error_reporting(E_ALL);
class mysql{
private $host;
private $user;
private $pwd;
private $dbName;
private $charset;
private $conn=null;
public function __construct(){
$this->host='localhost';
$this->user='root';
$this->pwd='123456';
$this->dbName='qian';
//连接
$this->connect($this->host,$this->user,$this->pwd);
//切换库
$this->dbSwitch($this->dbName);
//设置字符集
$this->setChar($this->charset);
}
//负责连接
private function connect($h,$u,$p){
$conn=mysql_connect($h,$u,$p);
$this->conn=$conn;
}
//负责切换数据库
public function dbSwitch($db){
$sql='use'.$db;
$this->query($sql);
}
//负责设置字符集
public function setChar($char){
$sql='set names'.$char;
$this->query($sql);
}
//负责发送SQL 查询
public function query($sql){
$sql= mysql_query($sql,$this->conn);
return $sql;
}
//负责获取多行多列的select结果
public function getAll($sql){
}
}
$db=new mysql();
$a='insert into rong (id,name,pwd) values (14,"我的文档","123456")';
$db->query($a);
if($db->query($a)){
echo "输入数据成功";
}else{echo "输入数据失败";}