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, I am very clear about the level of E-text. I hope you will not laugh at your teeth, but 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:
<? Php
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:
<? Php
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:
<? Php
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:
<? Php
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:
<? Php
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
<? Php
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
<? Php
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:
<? Php
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:
<? Php
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.
<? Php
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] <BR> ";
}
?>
5-Disconnect txtSQL
It is a good habit to disconnect the database after use. Disconnect the disconnect () function.
<? Php
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)