1
<?php
class mysql{
private $link;
private
$user ="root";
private $pwd ="";
private $db ="test";
private $charst ="utf8";
private $coon ="";
public function __construct($link = "localhost" ,$user=
"root",$pwd="lovo",$db="test",$charst="utf8"){
$this->link=$link;
$this->user=$user;
$this->pwd=$pwd;
$this->bd=$db;
$this->charst=$charst;
$this->coon=get_con();
}
public function get_con(){
//
$this->coon = mysql_connect($this->link,$this->user,$this->pwd) or
die(mysql_error());
$coon =
mysql_connect($this->link,$this->user,$this->pwd) or
die(mysql_error());
mysql_select_db($this->db,$this->coon);
mysql_query("set
names ‘$this->charst‘");
return $coon;
}
public function myquery1($sql){
$result =
mysql_query($sql);
return $result;
}
public function delete($sql){
$this->myquery1($sql);
return
mysql_affected_rows(); //如果执行删除成功,那么肯定有受影响的行数
// return $result;
}
public function insert($sql){
$this->myquery1($sql);
return
mysql_affected_rows();
// return $result;
}
}
$mysql = new mysql("localhost","root","","test","utf8");
?>
原文地址:http://www.cnblogs.com/cd-snoopy/p/3746528.html