An example of php calling database class
Release: 2016-07-25 09:04:38
Original
921 people have browsed it
-
-
/** - desc: Database class call instance Assume your data class is db_class.php
- link: bbs.it-home.org
- date: 2013/2/24
- */
- require_once("db_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 statements that do not return results
- $db->execute("insert into test01(name) values('This is a test!')");
- //$db->exec("");< /p>
//6. Execute a SQL statement that returns results
- $rs = $db->query("select * from test01");
// 7. Display the results in row format
- echo "
Display the result set in row format ";
- while($r = $db->fetch_row($rs)){
- echo $r[0 ].":".$r[1]."
";
- }
//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();
- ?>
-
Copy code
|
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
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31