PHP's MSSQL database connection class instance _php
Source: Internet
Author: User
KeywordsPhpmssql database connection class
In this paper, the example of the MSSQL database connection class PHP code, shared for everyone to reference.
The specific implementation code is as follows:
The code is as follows:
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
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 these: ' $db = new Db_sql_subclass; ' */ return 0; if (! $this->link_id) $this->connect ();
function Affected_rows () { Not a supported function in PHP3/4. Chris Johnson, 16may2001. Return Mssql_affected_rows ($this->query_id); $rsRows = Mssql_query ("SELECT @ @rowcount as rows", $this->link_id); if ($rsRows) { Return Mssql_result ($rsRows, 0, "rows"); } }
function Num_rows () { Return Mssql_num_rows ($this->query_id); }
function Num_fields () { Return Mssql_num_fields ($this->query_id); } function NF () { return $this->num_rows (); }
function np () { Print $this->num_rows (); }
function f ($Field _name) { return $this->record[strtolower ($Field _name)]; }
function P ($Field _name) { Print $this->f ($Field _name); }
function Halt ($msg) { printf (" Database Error:%s ", $msg); printf (" MSSQL Error:%s (%s) ", $this->errno, $this->error); Die ("Session halted."); } }
I hope this article is helpful to everyone's PHP programming.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.