In Linux, mSQL database development technology-general Linux technology-Linux programming and kernel information. The following is a detailed description. MSQL (mini SQL) is a single-user database management system. Because of its short and refined nature, its developed application systems are particularly favored by Internet users. I have developed a Web-based management system in Linux, which uses the mSQL database for data management. The system works well in actual operation. After summary, I will introduce the mSQL database development methods in Linux in detail.
First, you can download the latest version of the software free of charge after registering at www.hughes.com. au. The installation of mSQL is quite simple. The binary version (for software compiled on a hardware platform) is to expand the file to a user's directory and configure several parameters. For example, the file you downloaded is: mSQL-2.0.3.tar.gz, you want to install mSQL to the/usr/local directory, then we need to copy this file to the/usr/local directory, then type the command tar zxvf mSQL-2.0.3.tar.gz, which expands the compressed file. Generally, all files in the mSQL database system are installed in the/usr/local/Hughes directory. Configure the mSQL database. All you need to do is modify the file msql. conf in the/usr/local/Hughes directory.
In actual applications, the mSQL-User and Admin-User parameters are the most modified. MSQL-User indicates the User who runs the mSQL Database Service Program, and Admin-User indicates that the User can perform privileged operations on the mSQL database system (for example, closing the running of the Database Service Program and creating a database). Therefore, if you want the mSQL service program to run as a database User and specify the admin User to perform database operations, you need to change the rows of mSQL-User and Admin-User: mSQL-User = database and Admin-User = admin. In addition, you must change the owner of the files and directories under the Hughes directory to the database. After the configuration is complete, unregister the identity of the current user and re-use msql. the conf parameter mSQL-User sets the User to log on to the system, enter the/usr/local/Hughes/bin directory and type the following command :. /msql2d &, then the mSQL database system is started. For the installation software with source code, you can check the README and INSTALL files to complete the installation.
In order to integrate mSQL into the user's application, the mSQL database system provides users with a C language API library and an interpreter: w3-msql, through the C language API library, you can integrate mSQL into applications developed in Standard C language. With the w3-msql tool, you can write a C-language scripting language to embed the mSQL database into the html file, the following example of a program to illustrate.
The following program snippet is used to compare the user name and password submitted on the browser page with the user name and password in the registered-user table. If the user name and password are correct, the successful registration information is displayed on the page. Otherwise, the user registration fails. The method implemented in C language is as follows:
Void main (int argc, char? Argv [])
{
// Parse the user name and password submitted by the user and save it to the username and password-usr variables.
...
// Create a socket with the local mSQL Database System
Sock = msqlConnect (NULL );
// Select database test
If (msqlSelectDB (sock, "test") =-1)
{
// Output database selection Failure Information
...
} Else
{
Sprintf (buff, "select? From registered-user where username = '% S' ", username );
// Query records in the registered-user table with username
If (msqlQuery (sock, buff) =-1)
{
// Output the query failure error message
...
}
// Save the query result to the m-result type pointer variable res
Res = msqlStoreResult ();
// Obtain the number of records in the query result
Numrow = msqlNumRows (res );
If (numrow = 1)
{
// Obtain the current record; Type: m_row
Row = msqlFetchRow (res );
// Compare the password stored in the table with the password entered by the user
If (! Strcmp (password_ur, row [2])
{
// Output registration success Information
} Else
{
// Output prompt information with incorrect password
}
} Else
{
// Output error message for username Input
}
}
// Release the query result pointer
MsqlFreeResult (res );
// Close the socket of the Database System
MsqlClose (sock );
Return;
}
The above example contains the main functions used to integrate mSQL into C language programs. These functions can basically meet the needs of applications. If the use of w3-msql can be interpreted Class C language embedded into html files, can achieve the same function. Different from the CGI program compiled in C language, the script language does not need to be compiled. The script is interpreted and executed by the CGI program w3-msql provided by the mSQL database system. The main code segment in the script is as follows:
// Output prompt information with incorrect password
Echo ("center> the password you entered is incorrect </center> 〉″);
}
} Else
{
// Output error message for username Input
Echo ("center> the user name you entered is incorrect </center> 〉″);
}
}
// Release the memory occupied by query results
MsqlFreeResult ($ res );
// Close the socket of the Database System
MsqlClose ($ sock );
> 〉
</BODY> 〉
</HTML> 〉
The above describes how to develop an application system using the mSQL database system as the background database in Linux. With these basic methods, we can develop various mSQL database-based application systems.
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.