Summary: in linux, how does one mount the mysql. so extension in php? Background: We usually install mysql first before installing php. If you first install php and then install mysql, because php needs to connect to mysql, You need to configure the mysql. so extension in the php engine. In this case, you need to manually compile and generate the mysql. so extension. Current problem: in
Summary: in linux, how does one mount the mysql. so extension in php? Background: We usually install mysql first before installing php. If you first install php and then install mysql, because php needs to connect to mysql, You need to configure the mysql. so extension in the php engine. In this case, you need to manually compile and generate the mysql. so extension. Current problem: in
Summary: how to mount mysql. so extension in php in linux
Problem Background: We usually install mysql before installing php. If you first install php and then install mysql, because php needs to connect to mysql, You need to configure the mysql. so extension in the php engine. In this case, you need to manually compile and generate the mysql. so extension.
Current question: Can I use phpize to mount mysql. so extension in the above case?
Practice: Use the phpize tool to generate mysql. so, but add "-- with-mysql = mysql client path ". That is, the mysql. so module must use the mysql client.
As you can understand, mysql. so calls the mysql client internally to connect to the mysql database server.
The mysql_connect () that we often use may be that the mysql client can be called to connect to the database.
I. Why is the installation in the book usually in this order: Install mysql first, then install php, and seldom see install php first and then mysql?
In this way. Is based on the following reasons:
After installing mysql. Mysql. so can be generated. Remember the details: Provide the mysql path when installing php. Php helps compile and generate the mysql. so module. Mysql. so is generated when php is installed. One thing is required to generate this module:
Mysql client. If you install php first, then install mysql. Therefore, mysql. so cannot be mounted according to the original method (mysql. so module is generated with php help. Through practice, we found that using phpize tool to generate mysql. so can solve this problem.
Ii. Practice the process of generating mysql. so
General idea: You need to use the php source code package. Use the phpize file provided in the source code package (a tool specially attached to the php extension)
2011.3.6 successful
Run the command: phpize -- with-mysql =/usr/local/mysql/(mysql installation path)
Step 1: Go to the "ext/mysql" directory in the php source code
Command: cd
Step 2: Run phpize in the current directory
Command:/usr/local/php524/bin/phpize
Phpize rules: To which directory to run the phpize file, a configure file will be generated under this directory.
Step 3: run the configure file just generated
Command:./configure -- with-php-config =/usr/local/php524/bin/php-config -- with-mysql =/usr/local/mysql/
The most important thing here is to tell the location of the mysql client through the -- with-mysql parameter. In this way, mysql. so can be generated.
This parameter was not added during the experiment. The result is incorrect:
./Configure -- with-php-config =/usr/local/php524/bin/php-config
Step 4: compile and generate the. so file. What is ultimately required
Make
Make install
End /////////////////////////////////////// //////////////////
Step 5: configure the php engine to load the extension
Omitted
Add: modify the configuration in the php. ini file and load the mysql. so extension (this extension file should be placed under the extension directory specified by php)
Step 6: test whether the php engine successfully loads the extension
Compile the phpinfo. php file with the following content:
Ehco phpinfo ();
?>
After running, the following information is displayed:
Mysql
MySQL Support enabled
Active Persistent Links 0
Active Links 0
Client API version 5.1.55
MYSQL_MODULE_TYPE no value
MYSQL_SOCKET/tmp/mysql. sock
MYSQL_INCLUDE no value
MYSQL_LIBS no value
In this way, we can confirm that the php engine has successfully loaded the mysql. so extension.
Step 7: generated mysql. so. Write php code to test whether mysql can be connected
After step 6 is successful, we know that the php engine has successfully loaded the mysql. so extension. Check whether the generated extension works properly. Why? The. so extension can be generated even if compilation fails. In general, the. so extension encapsulates some functions for us to call.
. If some functions are not generated, the. so extension is also obtained. Maybe its. so module is incomplete. This was the case when I made a payment interface .. The so module contains functions encapsulated in c ++. The module has been generated. But it cannot run normally.
. Function exception. Later, we came up with the idea that it was successful to compile and generate a. so file.
It is necessary to test whether. so can be used. Now, test whether the generated mysql. so can be used.
Compile the following php code:
$ Conn = mysql_connect ("localhost", "root ","");
Mysql_select_db ("mysql", $ conn );
$ Results = mysql_query ("select * from user ");
$ Row = mysql_fetch_array ($ results );
Var_dump ($ row );
?>
Expected result (Part ):
Array
0 => string 'localhost' (length = 9)
'Host' => string 'localhost' (length = 9)
1 => string 'root' (length = 4)
'User' => string 'root' (length = 4)
2 => string ''(length = 0)
'Password' => string ''(length = 0)
3 => string 'y' (length = 1)
'Select _ priv' => string 'y' (length = 1)
4 => string 'y' (length = 1)
'Insert _ priv' => string 'y' (length = 1)
5 => string 'y' (length = 1)
'Update _ priv' => string 'y' (length = 1)
Note: The mysql. so extension after compilation can be used normally.
Inspiration: if the order for installing mysql and php is incorrect, it will increase a lot of trouble later. Therefore, in actual situations, some experienced users will "install php first and then mysql", which avoids the connection issue. Therefore, this is rarely required in practice.
For example, php and mysql have been installed. Php has been installed to install other databases such as oracle as needed. The idea is the same for compiling and generating an extension for other databases.