Learn PHP Technology: txtSQL Installation Manual Chinese version

Source: Internet
Author: User
Tags foreach empty error handling functions connect php class php file php and

One of the biggest advantages of txtsql is that the documentation is very detailed, unfortunately, I found on the internet for a long time also can not find the Chinese version of the document, so have to do their own, the benefit of the bar, but their own level of e-wen is very clear, I hope that we can not laughed just good, but also hope that we have a lot of advice.

Welcome to the txtSQL 2.2 quick installation manual. This page will show you how to start installing txtSQL.

1-Uncompressed Download package

2-Configuration class file

2.1-Directory structure

3-Include class files

3.1-class instance

3.2-Connecting to txtSQL

3.3-Change Password

3.4-Select a database

4-Execute SQL instructions

4.1-List of instructions

4.2-Show Results

5-Connect from disconnect txtSQL

6-Error handling

7-Published txtSQL function

1, Decompression download package

When you open the. zip file, you will notice that there are two files: txtSQL.class.php and txtSQL.core.php. Extracts two files to the same directory. Creates a new directory with any name, usually named data. This will be the directory that contains the database. It can be placed anywhere on the server, but it is usually located in the same directory as the above two files. Make sure that the directory permissions are 0755 or higher. Now return to the. zip file to find \ txtsql. Myi\ ' Extracts it to the database directory we just built. (Translator Note: In fact, not so much trouble, the. zip file has been organized, all extracted to any directory on the server, and set permissions on the line)

2. Configuration class file

Using the first step of txtSQL, configure the class file so that it can be included in the PHP file that might require it. First, you must open the file in a text editor txtSQL.class.php open the file, you will notice a copyright notice, followed by some other material. Then there is this line (the default is line 30th):

Include_once (\ './txtsql.core.php\ ');

This line of code makes it include txtSQL's core functions and classes. To facilitate PHP to find the core file, you must edit the single quotation mark inside the content, let it point to the txtSQL.core.php file. (Translator Note: This basically also does not need to set up, the source file already configured!) This is only necessary if your file is not in the same directory.

2.1, directory structure

A valid database directory structure should be like this:

+ datafolder (save directory for all databases, such as the newly created \ ' Data\ ')

+ database_name

+ table. FRM (column definition)

+ table. MyD (Row data)

+ txtSQL

+ txtSQL. Myi (Included in compressed package)

Basically, a database is a subdirectory of the primary database directory.

At the same time in the database directory is the TXTSQL database, compressed in the packet \ ' txtSQL. Myi\ ' I.

Within all databases, a datasheet consists of two files; FRM, and table. MyD.. FRM is the column definition and the other is the data row.

3. Include class files

Now that we have finished configuring txtSQL2.2, we can start using it. First use a text editor to create a blank php file. Save As example.php.

For a simple explanation, suppose you keep it in the same directory as \ ' Txtsql.class.php\ '.

Now we must include the PHP class and enter in \ ' example.php:

The following are the referenced contents:
<?php
Include (\ './txtsql.class.php\ ');
?>

3.1 Class instances

In object-oriented programming (OOP), when creating a class, a special variable type-an object is created automatically.

We need to create an object that points to the txtSQL class, and then add these to the file:

The following are the referenced contents:
<?php
Include (\ './txtsql.class.php\ ');
$sql = new txtSQL (\ './data\ ');
?>

The text in single quotes is the path to the data directory that contains all the databases. This directory must contain a txtsql (case sensitive) directory, the directory should have a \ ' txtSQL. Myi\ ' file. This file contains all the user and password for the operation database.

This directory and file are already in the txtSQL compression package. Once the path is correct, you can move on to the next paragraph.

3.2 Connection Database

Now we can connect to the database with the correct username and password.

The default username is Root\ ', and the default password is empty. (It is strongly recommended that you modify it in the following steps)

Use the following code to connect to the database:

The following are the referenced contents:
<?php
Include (\ './txtsql.class.php\ ');
$sql = new txtSQL (\ './data\ ');
$sql->connect ($username, $password); The default is $sql->connect (\ ' root\ ', \ ' \ ');
?>

txtSQL will then recognize that you are its user, allowing you access to databases and tables.

Note: A list of commands is available in the reference manual.

3.3. Change Password

If you want to change the admin password (root), you can use the Grant_permissions () function, the grant_permissions () function, to call:

The following are the referenced contents:
<?php
Include (\ './txtsql.class.php\ ');
$sql = new txtSQL (\ './data\ ');
$sql->connect ($username, $password); The default is $sql->connect (\ ' root\ ', \ ' \ ');
$sql->grant_permissions ($action, $user, $pass [, $newpass]);

The?> parameter $action (action) can be add (add), drop (delete), or edit (edit). $newpass (new password) is available only if you are editing (edit) a user.
$user (user) is the user name you want to manipulate, $pass is its password.

For example, if you want to change the user \ ' root\ ' password to \ ' bar\ ' (assuming it's still empty), we can do this:

The following are the referenced contents:
<?php
Include (\ './txtsql.class.php\ ');
$sql = new txtSQL (\ './data\ ');
$sql->connect ($username, $password); The default is $sql->connect (\ ' root\ ', \ ' \ ');
$sql->grant_permissions (\ ' edit\ ', \ ' root\ ', \ ' \ ', \ ' bar\ ');
?>

Or

Create a new user \ ' foo\ ' password for \ ' Bar\ '

The following are the referenced contents:
<?php
Include (\ './txtsql.class.php\ ');
$sql = new txtSQL (\ './data\ ');
$sql->connect ($username, $password); The default is $sql->connect (\ ' root\ ', \ ' \ ');
$sql->grant_permissions (\ ' add\ ', \ ' foo\ ', \ ' bar\ ');
?>

Or

Delete a user \ ' foo\ ' password for \ ' Bar\ '

The following are the referenced contents:
<?php
Include (\ './txtsql.class.php\ ');
$sql = new txtSQL (\ './data\ ');
$sql->connect ($username, $password); The default is $sql->connect (\ ' root\ ', \ ' \ ');
$sql->grant_permissions (\ ' drop\ ', \ ' foo\ ', \ ' bar\ ');
?>

Note: You do not have to delete user root\ ', and you cannot access any data without the correct password.

3.4. Select Database

Like MySQL, before you can manipulate a data table, you must first indicate which database it is in. This step is not necessary because you can specify which database to use when you operate.
We use the following statement to select a database:

The following are the referenced contents:
<?php
Include (\ './txtsql.class.php\ ');
$sql = new txtSQL (\ './data\ ');
$sql->connect ($username, $password); The default is $sql->connect (\ ' root\ ', \ ' \ ');
$sql->selectdb (\ ' test\ '); Selected database \ ' test\ '
?>

4. Execution instruction

Usually we just use the various methods of the $sql object to execute the instruction.
For example:

The following are the referenced contents:
<?php
Include (\ './txtsql.class.php\ ');
$sql = new txtSQL (\ './data\ ');
$sql->connect ($username, $password); The default is $sql->connect (\ ' root\ ', \ ' \ ');
$sql->selectdb (\ ' test\ '); Selected database \ ' test\ '
$results = $sql->select (Array (
\ ' db\ ' => \ ' test\ ',//This line is not necessary, because we have selected the database
\ ' table\ ' => \ ' test\ ',
\ ' where\ ' => array (\ ' id = 10\ ', \ ' and\ ', \ ' name =~ John smith\ '),
\ ' limit\ ' => array (0, 100)
));
?>

4.1. Instruction List

txtSQL2.2 supports the following directives:

The following are the referenced contents:
4.1-list of commands
Showdbs ()
Createdb ()
Dropdb ()
Renamedb ()
Select ()
Insert ()
Update ()
Delete ()
Showtables ()
CreateTable ()
Droptable ()
Altertable ()
Describe ()

You must connect to the database before executing the instruction, or you will have an error. Detailed instructions and examples (then translated) are used in the manual.

4.2, display the results

The $results variable now contains the information for the selected row in table test\.

You can use a loop to display all the results in the $results.

The following are the referenced contents:
<?php
Include (\ './txtsql.class.php\ ');
$sql = new txtSQL (\ './data\ ');
$sql->connect ($username, $password); The default is $sql->connect (\ ' root\ ', \ ' \ ');
$sql->selectdb (\ ' test\ '); Database \ ' Test\ ' is now selected
$results =
$sql->execute (\ ' select\ ',
Array (\ ' select\ ' => array (\ ' id\ ', \ ' name\ '),
\ ' db\ ' => \ ' test\ ',
\ ' table\ ' => \ ' test\ ',
\ ' where\ ' => array (\ ' id = 10\ ', \ ' and\ ', \ ' name =~ John smith\ '),
\ ' limit\ ' => array (0, 100)));
foreach ($results as $key => $row)
{
Print \ ID: $row [id], NAME: $row [name]<br>\n\];
}
?>

5-Disconnect txtSQL

It's a good habit to disconnect the database after you run out. Disconnect the Disconnect () function.

The following are the referenced contents:
<?php
Include (\ './txtsql.class.php\ ');
$sql = new txtSQL (\ './data\ ');
$sql->connect ($username, $password); The default is $sql->connect (\ ' root\ ', \ ' \ ');
$sql->selectdb (\ ' test\ '); Database \ ' Test\ ' is now selected
$results =
$sql->execute (\ ' select\ ',
Array (\ ' select\ ' => array (\ ' id\ ', \ ' name\ '),
\ ' db\ ' => \ ' test\ ',
\ ' table\ ' => \ ' test\ ',
\ ' where\ ' => array (\ ' id = 10\ ', \ ' and\ ', \ ' name =~ John smith\ '),
\ ' limit\ ' => array (0, 100)));
foreach ($results as $key => $row)
{
Print \ ID: $row [id], NAME: $row [name]<br>\n\];
}
$sql->disconnect ();
?>

6-Error handling

txtSQL contains error handling capabilities. The following functions are mainly used:

The following are the referenced contents:
Strict ()
Get_last_error ()
Last_error ()
Errordump ()



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.