mSQL database development technology under Linux

  
                              


mSQL (mini SQL) is a single-user database management system. Due to its shortness and precision, its application system is especially favored by Internet users. Web management system based on Linux, using mSQL database for data management, can achieve good running results.

The first is download. You can download the latest version of the software for free after registering at www.hughes.com.au.

The installation of mSQL is quite simple. The installation of the binary version (for a software compiled by a hardware platform) is just to expand the file to a directory of the user and then configure several parameters. For example, the file you downloaded is: mSQL-2.0.3.tar.gz. You want to install mSQL into the /usr/local directory. At this time, we need to copy this file to /usr/local and type The command tar zxvf mSQL-2.0.3.tar.gz, this command will expand the compressed file. In general, all files of the mSQL database system are installed in the /usr/local/Hughes directory. The next step is to configure the mSQL database. All you have to do is modify the file msql.conf in the /usr/local/Hughes directory.

In practice, we have changed the most parameters of mSQL-User and Admin-User. mSQL—User indicates the user running the mSQL database service program, and Admin—User indicates the user who can perform privileged operations on the mSQL database system (eg, shutting down the operation of the database server, creating a database, etc.). Therefore, if you want the mSQL server to run as the database user, specify the admin user to perform database operations, and change the line where mSQL_User and Admin_User are located: mSQL_User = database and Admin_User = admin. In addition, you must also change the owner of the files and directories under the Hughes directory to database. After the configuration is complete, log out the current user's identity, re-login to the system with the mSQL-User parameter mSQL-User, and enter the following command in the /usr/local/Hughes/bin directory: ./msql2d &, The mSQL database system is started. As for the installation software with source code, take a look at the README and INSTALL files can generally be successfully installed.

In order to integrate mSQL into the user's application, the mSQL database system provides the user with a C language API library and an interpreter: w3-msql, through the C language API library, you can mSQL is integrated into applications developed in standard C language. With the w3-msql tool, you can embed the mSQL database into the html file by writing a C-like scripting language. Let's take a program example to illustrate.

The function of the following program fragment is to compare the username and password submitted on the browser page with the username and password in the registered-user table. If the username and password are correct, they will be displayed on the page. Successful registration information, otherwise the user registration failed. The method implemented in C language is as follows:

void main(int argc, char argv[])
{
//Resolve the user name and password submitted by the user and save it to the variable username And password-usr

...

//Create a socket with the native 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 the table registered_user record with username
if (msqlQuery(sock ,buff)==-1)
{
//Output query failed error message

...

}

//Save the query result to The pointer variable of the m-result type res

res=msqlStoreResult();

//The number of records that get the result of the query

n Umrow=msqlNumRows(res);
if (numrow==1)
{
//Get the current record, type: m_row
row=msqlFetchRow(res);
//will The password stored in the table is compared with the password entered by the user
if (!strcmp(password_ur,row[2]))
{
//Output registration success message
} else
{
//Output message with incorrect password

}
} else
{
//Output user name input error message
}
}
//Release the pointer of the query results
msqlFreeResult (res);
//Close the database system socket
msqlClose (sock);
return;
}

The above examples contain the main functions used to integrate mSQL into C programs, which basically meet the needs of the application. If you use the class C language that w3-msql can interpret into the html file, you can achieve the same function. CGI programs written in C language need to be compiled differently. 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 script code fragment is as follows:



{
//Output database selection failure message
fatal ("Error: Unable to connect to database \ ");
} else
{
$buff = " select  from registered—user where username='$username ′′;
//Query the record in the register-user with the username
if (msqlQuery($s Ock, $buff) ==-1)
{
//Output error message for query failure
fatal ("query error \ ");
}
//will query The result is saved to the pointer variable res of the query result
$res=msqlStoreResult();
//The number of records that get the result of the query
$numrow=msqlNumRows($res);
if ($ Numrow==1)
{
//Get the pointer to 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 message
echo("") ;
} else
{
//Output password error message
echo("

The password you entered is incorrect
");
}
} else
{
//Output username input error message
echo("
The entered username is incorrect
");
}
}
//Release the memory occupied by the query result
msqlFreeResult($res);
//Close the database system Socket
msqlClose($sock);

〈/BODY>
〈/HTML〉zh-CN"],null,[1],zh-TW"]]]
Copyright © Windows knowledge All Rights Reserved