CREATE TABLE IF NOT EXISTS `test_mysql` ( `id` int(11) NOT NULL AUTO_INCREMENT, `from_user` varchar(40) DEFAULT NULL, `account` varchar(40) DEFAULT NULL, `password` varchar(40) DEFAULT NULL, `update_time` datetime DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `from_user` (`from_user`));
<!--?php
require_once 'includes/configure.php';
class MySQLi_BAE{
private $mysqli;
private $host;
private $user;
private $password;
private $port;
private $database;
//在类之外访问私有变量时使用
function __get($property_name){
if(isset($this--->$property_name)){
return($this->$property_name);
}else{
return(NULL);
}
}
function __set($property_name, $value){
$this->$property_name=$value;
}
function __construct(){
/*从平台获取查询要连接的数据库名称*/
$this->database = MYSQLNAME;
/*从环境变量里取出数据库连接需要的参数*/
$this->host = getenv('HTTP_BAE_ENV_ADDR_SQL_IP');
$this->user = getenv('HTTP_BAE_ENV_AK');
$this->password = getenv('HTTP_BAE_ENV_SK');
$this->port = getenv('HTTP_BAE_ENV_ADDR_SQL_PORT');
$this->mysqli = new mysqli($this->host, $this->user, $this->password, $this->database, $this->port);
if($this->mysqli->connect_error){
die("Connect Server Failed:".$this->mysqli->error);
}
$this->mysqli->query("set names utf8");
}
//dql statement
function execute_dql($query){
$res = $this->mysqli->query($query) or die("操作失败".$this->mysqli->error);
return $res;
//$this->mysqli->close();
}
//dml statement
function execute_dml($query){
$res = $this->mysqli->query($query) or die("操作失败".$this->mysqli->error);
if(!$res){
return 0;//失败
}else{
if($this->mysqli->affected_rows > 0){
return 1;//执行成功
}else{
return 2;//没有行受影响
}
}
//$this->mysqli->close();
}
}
?>
<!--?php
require_once "MySQLi_BAE.class.php";
$mysqli_BAE=new MySQLi_BAE();
//**************dml*******************
$sql="insert into test_mysql (from_user, account, password, update_time) values('David','860510', 'abcabc', '2013-09-27 17:14:28')";
//$sql="update test_mysql set account = 860512 where account = 860510";
//$sql="delete from test_mysql where account = 860512";
$res=$mysqli_BAE--->execute_dml($sql);
if($res==0){
echo "执行失败";
}elseif($res==1){
echo "执行成功";
}else{
echo "没有行数影响";
}
?>
<!--?php
require_once "MySQLi_BAE.class.php";
$mysqli_BAE=new MySQLi_BAE();
//**************dql******************
$sql="select * from test_mysql";
$res=$mysqli_BAE--->execute_dql($sql);
while($row=$res->fetch_row()){
foreach($row as $key=>$val){
echo "$val--";
}
echo '
';
}
$res->free();
?>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有