VB connect SQL database with Dbsql class to speed up the development of MySQL database program

Source: Internet
Author: User
When you write access to MySQL database program, is not very troublesome: a large set of functions and parameters, but also to check the results of the call, the more headaches is that each program contains the database name, user, password, etc., want to modify is not easy. But if you use the Dbsql class in Phplib, these problems will be solved. This article will teach you how to use the Dbsql class.
I. Acquisition of DBSQL
How to get dbsql, there are two ways:
-Since Dbsql is part of phplib, you can download a copy of phplib from this site or http://phplib.netuse.de
-Download Dbsql class directly from this site, I have made it independent and made some minor changes. Download Address: http://www.phpuser.com/programs_and_code/codedetail.php?id=3
Second, modify the Dbsql file.
Open the file, find about 138 lines, change the $host, $Database, $User, $Password and other four variables to the value on your machine.
Third, the use of Dbsql
As simple as that can come in handy, here is a typical example (here we assume that the Dbsql class is stored in the db.php file):
Require "db.php";
$db =new Dbsql;
$db->connect ();
if ($db->link_id)
{
$db->query ("Select ID, name from contact WHERE ID > + ID
< 200 ");
if ($db->nf ())
{
($db->next_record ())
{
echo "id=", $db->f ("id");
echo "
";
echo "Name";
One $db->p (' name ');
echo "
";
}
}
$db->free_result ();
}
?>
Let me explain it on a row-by-line basis:
01-Include the db.php file in
02-Create an instance of the Dbsql class with the variable name: $db
03-Call Dbsql's Connect () method to connect to the database. This line works with Mysql_pconnect (host,
DB, passwd)
04-Determine if the connection was successful by checking the value of the $db property link_id. Generally as long as the configuration is not a problem, this step can be omitted
05-If the connection is not a problem, call the Dbsql class's Query method to execute the query
The NF () function of the 06-dbsql class returns the number of records returned after the query, as with Mysql_num_rows (). If a record is found, continue execution
07-Use a while loop with the Dbsql Next_record () method as the condition. The Next_record () method moves the pointer of the result of the Dbsql class down one line, and if it ends, it returns a false value
08-Use the F () method of the Dbsql class to retrieve the value of a field in the current row of the query result. The parameter of the method is the name of the field, such as $DB-&GT;F ("id")
11-Use the P () method of the Dbsql class. The P () method differs from the F () method in that it directly outputs the value of a field in the current row of the query result. The parameter of the method is the same as the F () method and the name of the field, such as $db->p ("id")
13-Frees the memory that PHP uses. Equivalent to calling the Mysql_free_result function
The basic usage of dbsql is this, and of course there are others, which I will introduce below.
Iv. Other Content
Auto_free property: If set to true, when the call Next_record () method reaches the end of the query result, Dbsql automatically executes the Free_result () method, releasing the memory DebugMode property that is used: if set to True, the query () is executed method, the SQL statement of the query is printed, so it is especially useful when doing debugging
Seek () method: Move a pointer to the DBSQL query result, the first 0
Num_rows () Method: As with the NF () method, the number of records that returned the result of the query
Metadata () Method: Returns an array that includes the results of the table as a parameter of the table name

The above describes the VB connection SQL database with the Dbsql class to speed up the development of the MySQL database program, including the VB connection SQL database content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    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.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.