Home > Backend Development > PHP Tutorial > PHP database call class call example (detailed comments)_PHP tutorial

PHP database call class call example (detailed comments)_PHP tutorial

WBOY
Release: 2016-07-21 15:17:55
Original
840 people have browsed it

Copy code The code is as follows:

require_once("mssql.class.php");
//1. Create a class and connect to the database
$db = new mssql("dns=aaa;uid=sa;pwd=sa;dbname=test");
//2. Connect to the database
$conn = $db->config("dns=aaa;uid=sa;pwd=sa;dbname=test");
///3. Select database
$dbname = $db->select_db ("test");
//4. Set to allow debugging
$db->debug = true;
//5. Execute a SQL statement that does not return a result
$db-> ;execute("insert into test01(name) values('This is a test!')");
//$db->exec("");
//6. Execute a return result SQL statement
$rs = $db->query("select * from test01");
///7. Display the results in row format
echo "
Display the results in row format set
";
while($r = $db->fetch_row($rs)){
echo $r[0].":".$r[1]."< br>";
}

//8. Display the results in array format
$rs2 = $db->query("select * from test01");

echo "
Display the result set in array format
";
while($r = $db->fetch_array($rs2)){
echo $r["id"] . ":" . $r["name"] . "
";
}

//X. Release
$db->db_close();

?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325665.htmlTechArticleCopy the code as follows: ?PHP require_once("mssql.class.php"); //1. Create a class , and connect to the database $db = new mssql("dns=aaa;uid=sa;pwd=sa;dbname=test"); //2. Connect to the database $conn =...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template