手机版

php入门之连接关系型数据库数据库的一个类

时间:2021-10-09 来源:互联网 编辑:宝哥软件园 浏览:

项目结构

运行效果;

conn.php复制代码代码如下:服务器端编程语言(Professional Hypertext Preprocessor的缩写)类ConnectionMySQL{ //主机private $ host=' localhost//数据库的用户名private $ name=' root//数据库的密码私有$ pass=//数据库名称private $ table=' phptest//编码形式private $ ut=' utf-8 ';//构造函数function _ _ construct(){ $ this-ut=$ ut;$ this-connect();} //数据库的链接函数connect(){ $ link=MySQL _ connect($ this-host,$this-name,$this-pass)或die($ this-error());mysql_select_db($this-table,$link)或' die('没该数据库:'.$ this-table);MySQL _ query(' SET NAMES ' $ this-ut ' ');}函数查询($sql,$type='') { if(!($ query=MySQL _ query($ SQL)))$ this-show(' Say : ',$ SQL);返回$ query}函数show($message=' ',$sql='') { if(!$sql)回显$消息;else echo $消息br .$ sql}函数impact _ rows(){ return MySQL _ impact _ rows();}函数结果($query,$ row){返回MySQL _ result($ query,$ row);}函数num _ rows($ query){ return @ MySQL _ num _ rows($ query);} function num _ fields($ query){ return MySQL _ num _ fields($ query);}函数free _ result($ query){ return MySQL _ free _ result($ query);}函数insert _ id(){返回MySQL _ insert _ id();}函数fetch _ row($ query){ return MySQL _ fetch _ row($ query);}函数版本(){返回MySQL _ get _ server _ info();}函数close(){ return MySQL _ close();} //向$表表中插入值函数fn_insert($table,$name,$ value){ $ this-query(' insert in $ table($ name)value($ value)');} //根据$id值删除表$表中的一条记录函数fn_delete($table,$id,$value){ $this-query('从$表中删除,其中$ id=$ value’);回声编号为$id .' 的记录被成功删除!';} } $ db=new ConnectionMySQL();$db-fn_insert('test ',' id,name,sex ',''',' hongtenzone ',' M ');$db-fn_delete('test ',' id ',1);

版权声明:php入门之连接关系型数据库数据库的一个类是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。