In PHP development, we often need to use some database classes. here we will briefly share the code for calling classes. For more information about php database operations, see
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 a database
$ Dbname = $ db-> select_db ("test ");
// 4. allow debugging
$ Db-> debug = true;
// 5. execute an SQL statement that does not return results
$ Db-> execute ("insert into test01 (name) values ('this is a test! ')");
// $ Db-> exec ("");
// 6. execute an SQL statement that returns the result
$ Rs = $ db-> query ("select * from test01 ");
// 7. display results in row mode
Echo"
Display result sets in row mode
";
While ($ r = $ db-> fetch_row ($ rs )){
Echo $ r [0]. ":". $ r [1]."
";
}
// 8. display results in array mode
$ Rs2 = $ db-> query ("select * from test01 ");
Echo"
Display result sets in array mode
";
While ($ r = $ db-> fetch_array ($ rs2 )){
Echo $ r ["id"]. ":". $ r ["name"]."
";
}
// X. release
$ Db-> db_close ();
?>