PHP Tutorial MSSQL Database Tutorial Connection Class code
| The code is as follows |
Copy Code |
|
Class Db_sql {
var $Host = "";
var $Database = "";
var $User = "";
var $Password = "";
var $Link _id = 0;
var $Query _id = 0;
var $Record = array ();
var $Row = 0;
var $Errno = 0;
var $Error = "";
var $Auto _free = 0; # # Set this to 1 to automatically free results
* Public:constructorwww.111cn.net * *
function Db_sql ($query = "") {
$this->query ($query);
}
function Connect () {
if (0 = = $this->link_id) {
$this->link_id=mssql_connect ($this->host, $this->user, $this->password);
if (! $this->link_id)
$this->halt ("Link-id = = False, Mssql_pconnect failed");
Else
@mssql_select_db ($this->database, $this->link_id);
}
}
function Free_result () {
Mssql_free_result ($this->query_id);
$this->query_id = 0;
}
function query ($Query _string)
{
/* No empty queries, please, since PHP4 chokes on them. */
if ($Query _string = "")
/* The empty query string is passed on from the constructor,
* When calling the class without a query, e.g. in situations
* like: ' $db = new Db_sql_subclass; '
*/
return 0;
if (! $this->link_id)
$this->connect ();
# printf ("<br>debug:query =%s<br>", $Query _string);
|