mysql类

发布时间:2014-07-10 18:11:31 阅读:1213次

phpmysql.php

<?php

#$conn=mysql_connect("localhost","root","123456");
#mysql_select_db("pps");
#$sql="SELECT *FROM pic";
#$query=mysql_query($sql);
#$row=mysql_fetch_assoc($query);
#echo "<pre>";
#print_r($row);
#echo "</pre>";
//mysql_close($conn);
class mysql{
private $host="127.0.0.1";
private $user="root";
private $pwd="123456";
private $db="pps";
private $conn;
static $connect;
function __construct(){
//if(!self::$connect){
echo "connect";
$this->connect();
self::$connect=TRUE;
//}
}
function connect(){
$host=$this->host;
$user=$this->user;
$pwd=$this->pwd;
$this->conn=mysql_connect($host,$user,$pwd);
$db=mysql_select_db($this->db,$this->conn);
}
function query($sql,$type=""){
$query=mysql_query($sql);
if($type){
if($type=="assoc"){
$row=mysql_fetch_assoc($query);
}elseif($type=="all"){
$i=0;
while($array=mysql_fetch_assoc($query)){
$i=$i+1;
$row[$i]=$array;
}
}elseif($type=="1"){
$row=mysql_fetch_row($query);
$row=$row[0];
}
}else{
mysql_query($sql);
}
return $row;
}
function __destruct(){
mysql_close($this->conn);
}
}
/*$mysql=new mysql;
$array=$mysql->query("select addtime from pic","assoc"); 
echo "<pre>";
print_r($array);
echo "</pre>";
$array=$mysql->query("select addtime from pic","assoc"); 
echo "<pre>";
print_r($array);

echo "</pre>";*/

?>

class.php

<?php
include "phpmysql.php";
class php extends mysql{
function __construct(){
parent::__construct();
}
function get_test(){
$row=$this->query("select *from pic","all");
return $row;
}
}
$php=new php;
$row=$php->get_test();
echo "<pre>";
print_r($row);
echo "</pre>";

?>

如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询
上一篇:php魔法函数
下一篇:类属性遍历

转载请注明:mysql类 出自老鄢博客 | 欢迎分享