Msql Database Development Technology in Linux

Source: Internet
Author: User
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 installation of the binary version (for software compiled on a hardware platform) is only
Is to expand the file to a user 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 first
Copy the file to the/usr/local directory, and then type the command tar zxvf msql-
2.0.3.tar.gz. This command expands the compressed file. Generally, all files in the msql database system are
Install it in the/usr/local/Hughes directory. Configure the msql database. All you have to do is
Is to 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 to run the msql database service.ProgramAdmin-user indicates that
Users who perform privileged operations (such as shutting down the running of database service programs and creating databases. Because
If you want the msql service program to run as the database user, specify the admin user to execute
For row database operations, you need to change the rows in which msql-user and admin-user are located to: msql-user =
Database and admin-user = admin. In addition, you must add the files and directory owner under the Hughes directory
Change master to database. After the configuration is complete, unregister the identity of the current user and re-use the msql. conf Parameter
The user set by msql-user logs on to the system and enters the/usr/local/Hughes/bin directory.
Command:./msql2d &, then the msql database system is started. For installation software with source code, see
The readme and install files can be successfully installed.

To integrate msql into your applications, the msql database system provides
Language api library and an interpreter: w3-msql, through the C language api library, you can integrate msql
Go to the applications developed in the Standard C language. With the w3-msql tool, you can write Class C Language
The script language embeds the msql database into an HTML file. The following is an example of a program.

The following program snippet is used to submit the user name, password, and table on the browser page.
The username and password in registered-user are compared. If the username and password are correct
The message indicating successful registration is displayed. Otherwise, the user fails to register. 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 preceding example contains the main functions used to integrate msql into a C language program.
Can meet the needs of applications. If the use of w3-msql can be interpreted Class C language embedded into the HTML file, you can
To 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. MainCodeSegment
As follows:

<HTML> 〉

<Head> 〉

<Meta HTTP-EQUIV = "Content-Type" content = "text/html; charset = iso-
8859-1 "> ″〉

</Head> 〉

<Body text = "#000000" background = "/icon/back.jpg" topmargin = "10"> ″〉

<〈!

// Parse the user name and password submitted by the user and

Save to the username and password-USR Variables

...

// Create a socket with the local msql Database System

$ Sock = msqlconnect ();

// Select database Test

If (msqlselectdb ($ sock, "test") =-1)

{

// Output database selection Failure Information

Fatal ("error: Unable to connect to Database ″);

} Else

{

$ Buff = "select from registered-user where username = '$ Username ′″;

// Query records in the registered-User table with Username

If (msqlquery ($ sock, $ buff) =-1)

{

// Output the query failure error message

Fatal ("query error N ″);

}

// Save the query result to res, the pointer variable of the query result.

$ Res = msqlstoreresult ();

// Obtain the number of records in the query result

$ Numrow = msqlnumrows ($ res );

If ($ numrow = 1)

{

// Get the pointer of the current record

$ 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

Echo ("center> registered successfully </center> 〉″);

} Else

{

// 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.
Method. With these basic methods, we can develop various msql database-based application systems.

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.