Learn PHP Technology: Chinese version of txtSQL Installation Manual. One of the biggest advantages of txtsql is that the documentation is very detailed. Unfortunately, I couldn't find the Chinese version of the documentation for a long time on the Internet, so I had to do it myself, however, one of the biggest advantages of my E-level txtsql is that the documentation is very detailed. Unfortunately, I have not found the Chinese version of the documentation for a long time on the Internet, so I had to do it myself, li lialready, but his E-level is very clear. I hope you will not smile at it, and I hope you will give me more advice.
Welcome to txtSQL 2.2 Quick Installation Manual. This page shows you how to install txtSQL.
1-extract the downloaded package
2-configuration files
2.1-directory structure
3-include class files
3.1-class instance
3.2-connect to txtSQL
3.3-change password
3.4-select a database
4-execute SQL commands
4.1-command list
4.2-display results
5-disconnect txtSQL
6-error handling
7-released txtSQL functions
1. decompress the downloaded package
When you open the. zip file, you will notice two files: txtSQL. class. php and txtSQL. core. php. Extract two files to the same directory. Create a new directory named data. This will be the directory containing the database. It can be stored anywhere on the server, but it is usually located in the same directory of the above two files. Make sure that the directory has 0755 or higher permissions. Now, go back to the. zip file and find xtsql. MYI to extract it to the Database Directory we just created. (Note: the. zip file has been organized, all of which can be decompressed to any directory on the server, and permissions can be set)
2. configuration files
The first step of using txtSQL is to configure the class file so that it can be included in the PHP file that may require it. First, you must open the file txtSQL. class. php in the text editor. when opening the file, you will notice a copyright statement, followed by some other materials. Then there will be such a row (the default is 30th rows ):
30. include_once (./txtSQL. core. php );
This line of code includes the core functions and classes of txtSQL. To help php find the core file, you must edit the content in single quotes to point it to the txtSQL. core. php file. (Note: You do not need to set this parameter. the source file is already configured! This is required only when your files are not in the same directory)
2.1. directory structure
A valid Database Directory structure should be as follows:
+ Datafolder (storage directory of all databases, such as the data created above)
+ Database_name
+ Table. FRM (Column definition)
+ Table. MYD (row data)
+ Txtsql
+ Txtsql. MYI (included in the compressed package)
Basically, a database is a sub-directory under the main database directory.
At the same time, the txtsql database is in the database directory, and xtsql. MYII is in the compressed package.
Within all databases, a data table consists of two files: table. FRM, and table. MYD .. FRM is the column definition, and the other is the data row.
3. include class files
Now that txtSQL2.2 has been configured, we can start using it. First, use the text editor to create a blank php file. Save as example. php.
For a simple description, suppose you save it in the same directory as xtSQL. class. php.
Now we must include the php class. in example. php, enter:
Include (./txtSQL. class. php );
?>
3.1 Class instances
In object-oriented programming (OOP), when a class is created, a special variable type-an object is automatically created.
We need to create an object pointing to the txtSQL class, then add these to the file:
Include (./txtSQL. class. php );
$ SQL = new txtSQL (./data );
?>
The text in single quotes is the path that contains the data directories of all databases. This directory must contain a txtsql (case sensitive) directory, which should contain an xtsql. MYI file. This file contains all users and passwords of the operating database.
This directory and file are already in the txtSQL compressed package. Once the path is correct, you can proceed to the next section.
3.2 connect to the database
Now we can use the correct user name and password to connect to the database.
The default username is root, and the default password is null. (It is strongly recommended that you modify it in the following steps)
Use the following code to connect to the database:
Include (./txtSQL. class. php );
$ SQL = new txtSQL (./data );
$ SQL-> connect ($ username, $ password); // The default value is $ SQL-> connect (oot ,\);
?>
TxtSQl recognizes you as a user and allows you to access databases and tables.
Note: the reference manual contains a list of available commands.
3.3 Change password
If you want to change the administrator password (root), you can use the grant_permissions () function and the grant_permissions () function to call it like this:
Include (./txtSQL. class. php );
$ SQL = new txtSQL (./data );
$ SQL-> connect ($ username, $ password); // default is $ SQL-> connect (oot ,\);
$ SQL-> grant_permissions ($ action, $ user, $ pass [, $ newpass]);
?> The $ action parameter can be add, drop, or edit ). $ newpass (new password) is only available when you edit a user. $ User is the user name you want to operate on, and $ pass is the password.
For example, if you want to change the user's oot password to ar (assuming it is still empty), we can do this:
Include (./txtSQL. class. php );
$ SQL = new txtSQL (./data );
$ SQL-> connect ($ username, $ password); // default is $ SQL-> connect (oot ,\);
$ SQL-> grant_permissions (edit, oot, \, ar );
?>
Or
Create a user with the foo password ar
Include (./txtSQL. class. php );
$ SQL = new txtSQL (./data );
$ SQL-> connect ($ username, $ password); // default is $ SQL-> connect (oot ,\);
$ SQL-> grant_permissions (add, foo, ar );
?> Or
Delete a user whose foo password is ar
Include (./txtSQL. class. php );
$ SQL = new txtSQL (./data );
$ SQL-> connect ($ username, $ password); // default is $ SQL-> connect (oot ,\);
$ SQL-> grant_permissions (drop, foo, ar );
?> Note: You do not need to delete the user root. if you do not have the correct password, you cannot access any data.
3.4 Select a database
Like mySQL, before operating a data table, you must first describe which database it belongs to. This step is not required, because you can specify which database to use during the operation.
Use the following statement to select a database:
Include (./txtSQL. class. php );
$ SQL = new txtSQL (./data );
$ SQL-> connect ($ username, $ password); // default is $ SQL-> connect (oot ,\);
$ SQL-> selectdb (est); // you have selected the database est.
?>
4. execute commands
Generally, we only need to execute commands using various methods of the $ SQL object.
For example:
Include (./txtSQL. class. php );
$ SQL = new txtSQL (./data );
$ SQL-> connect ($ username, $ password); // default is $ SQL-> connect (oot ,\);
$ SQL-> selectdb (est); // you have selected the database est.
$ Results = $ SQL-> select (array (
Db => est, // This line is not required, because we have selected the database
Able => est,
Where => array (id = 10, and, ame = ~ John Smith ),
Limit => array (0,100)
));
?>
4.1. Command list
TxtSQL2.2 supports the following commands:
4.1-List of commands
Showdbs ()
Createdb ()
Dropdb ()
Renamedb ()
Select ()
Insert ()
Update ()
Delete ()
Showtables ()
Createtable ()
Droptable ()
Altertable ()
Describe ()
Before executing the command, you must connect to the database. Otherwise, an error will occur. Detailed instructions and examples (subsequently translated) will be used in the manual ).
4.2. display results
The $ results variable contains information about the row selected in the test table.
You can use a loop to display all the results in $ results.
Include (./txtSQL. class. php );
$ SQL = new txtSQL (./data );
$ SQL-> connect ($ username, $ password); // default is $ SQL-> connect (oot ,\);
$ SQL-> selectdb (est); // database est is now selected
$ Results =
$ SQL-> execute (select,
Array (select => array (id, ame ),
Db => est,
Able => est,
Where => array (id = 10, and, ame = ~ John Smith ),
Limit => array (0,100 ))));
Foreach ($ results as $ key => $ row)
{
Print "ID: $ row [id], NAME: $ row [name]
";
}
?>
5-disconnect txtSQL
It is a good habit to disconnect the database after use. Disconnect the disconnect () function.
Include (./txtSQL. class. php );
$ SQL = new txtSQL (./data );
$ SQL-> connect ($ username, $ password); // default is $ SQL-> connect (oot ,\);
$ SQL-> selectdb (est); // database est is now selected
$ Results =
$ SQL-> execute (select,
Array (select => array (id, ame ),
Db => est,
Able => est,
Where => array (id = 10, and, ame = ~ John Smith ),
Limit => array (0,100 ))));
Foreach ($ results as $ key => $ row)
...