Home > php教程 > php手册 > php简单的数据库连接类程序

php简单的数据库连接类程序

WBOY
Release: 2016-06-13 09:49:21
Original
1119 people have browsed it

一个不错的简单的数据库连接类程序,有需php mysql数据库连接类的同学可参考本文章。

 代码如下 复制代码


require_once("mssql.class.php");
//1.创建类,并连接数据库
$db = new mssql("dns=aaa;uid=sa;pwd=sa;dbname=test");
//2.连接数据库
$conn = $db->config("dns=aaa;uid=sa;pwd=sa;dbname=test");
//3.选择数据库
$dbname = $db->select_db("test");
//4.设置允许调试
$db->debug = true;
//5.执行一条不返回结果的SQL语句
$db->execute("insert into test01(name) values('这是一个测试!')");
//$db->exec("");
//6.执行一条返回结果的SQL语句
$rs = $db->query("select * from test01");
//7.以row方式显示结果
echo "
以row方式显示结果集
";
while($r = $db->fetch_row($rs)){
 echo $r[0].":".$r[1]."
";
}

//8.以array方式显示结果
$rs2 = $db->query("select * from test01");

echo "
以array方式显示结果集
";
while($r = $db->fetch_array($rs2)){
 echo $r["id"] . ":" . $r["name"] . "
";
}

//X.释放
$db->db_close();

?>


 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template