php面向对象的思想编写mysql

/建立连接/
class database{
/初始化数据/
public iP=xx;public i P = ” x x ” ; p u b l i c username=”xx”;
public psw=xx;public p s w = ” x x ” ; p u b l i c charType=”xx”;
public $selectDb=”xx”;
/连接mysql/
function link_mysql(){
mysql_connect( this>iP, t h i s − > i P , this->username, this>psw);mysqlsetcharset( t h i s − > p s w ) ; m y s q l s e t c h a r s e t ( this->charType);
mysql_select_db($this->selectDb);
}
/构造函数/
function __construct( a, a , b, c, c , d,e){ e){ this->iP= a; a ; this->username= b; b ; this->psw= c; c ; this->charType= d; d ; this->selectDb=$e;
}
}

//然后是mysql执行语句:
class sql {
public $sql=”xx”;
/检查语句是否正确如果正确就打印出来/
function sqlword(){
sql1= s q l 1 = this->sql;
result=mysqlquery( r e s u l t = m y s q l q u e r y ( sql1);
if(result===false){  
                echo mysql_error();   
            }  
            else{  
                //echo
result===false){                  echo mysql_error();               }              else{                  //echo
_SERVER[‘QUERY_STRING’];
num=mysqlnumfields( n u m = m y s q l n u m f i e l d s ( result);
echo “

“;
/ 这是表头/
echo ““;
for( i=0; i = 0 ; i< num; n u m ; i++){
fieldName=mysqlfieldname( f i e l d N a m e = m y s q l f i e l d n a m e ( result,$i);
echo ““;
}
echo ““;
/ 这是数据库信息/
while( re=mysqlfetcharray( r e = m y s q l f e t c h a r r a y ( result)){
echo ““;
for( i=0; i = 0 ; i< num; n u m ; i++){
fieldName=mysqlfieldname( f i e l d N a m e = m y s q l f i e l d n a m e ( result,$i);
echo ““;
}
echo ““;
}
echo “
“.$fieldName.”
“. re[ r e [ fieldName].”
“;
}
}
/ 构造函数/
function __construct( g){  
            //parent::__construct();
g){              //parent::__construct();
this->sql=$g;
}
}

/*mysql_num_fields 是取得结果集中字段的数目 用法:mysql_num_fields ( result)mysqlfieldnamemysqlfieldname( r e s u l t ) m y s q l f i e l d n a m e 是 取 得 结 果 中 指 定 字 段 的 字 段 名 用 法 : m y s q l f i e l d n a m e ( result , fieldindex)mysqlfetcharraymysqlnumfields( f i e l d i n d e x ) m y s q l f e t c h a r r a y 是 从 结 果 集 中 取 得 一 行 作 为 关 联 数 组 用 法 : m y s q l n u m f i e l d s ( result )*/

最后是建立对象:

/连接/
final=newdatabase(localhost,root,123,utf8,task04); f i n a l = n e w d a t a b a s e ( “ l o c a l h o s t ” , ” r o o t ” , ” 123 ” , ” u t f 8 ” , ” t a s k 04 ” ) ; final->link_mysql();
/选择数据库/
new sql(“use task04”);
/对数据库里面的文件进行操作/
$final2=new sql(“select * from list”);
/打印在页面上/
echo $final2->sqlword();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值