php 5.2.3+mysqli 安裝與常見錯誤 總結

php 5.2.3+mysqli 安裝與常見錯誤 總結
 
記得原來在編譯php的已經已經加上參數
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
可後來找了一個,的確不存在mysqli.so,因此只能單獨來編譯mysqli了。
mysqli是優化過的mysql函數庫,MYSQL版本不能低於4.1.12

cd /root/tmp/php-5.2.3/ext/mysqli
#####進入到mysqli的目錄。
再用phpize生成configure文件:
/usr/local/bin/phpize
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20060613
Zend Extension Api No:   220060519
#./configure --prefix=/usr/local/mysqli --with-php-config=/usr/local/bin/php-config --with-mysqli=/usr/bin/mysql_config
make
make install
Installing shared extensions:     /usr/local/lib/php/extensions/debug-non-zts-20060613/
而後在/usr/local/lib/php.ini
加上一句:
extension=/usr/local/lib/php/extensions/no-debug-non-zts-20060613/mysqli.so
從新啓動apache便可看到已經加載mysqli成功。
 
 
一、若是出現出錯代碼:
 
 
  1. /root/tmp/php-5.2.3/ext/mysqli/mysqli.c: In function 'zm_startup_mysqli':
  2. /root/tmp/php-5.2.3/ext/mysqli/mysqli.c:637: error: 'MYSQL_RPL_MASTER' undeclared (first use in this function)
  3. /root/tmp/php-5.2.3/ext/mysqli/mysqli.c:637: error: (Each undeclared identifier is reported only once
  4. /root/tmp/php-5.2.3/ext/mysqli/mysqli.c:637: error: for each function it appears in.)
  5. /root/tmp/php-5.2.3/ext/mysqli/mysqli.c:638: error: 'MYSQL_RPL_SLAVE' undeclared (first use in this function)
  6. /root/tmp/php-5.2.3/ext/mysqli/mysqli.c:639: error: 'MYSQL_RPL_ADMIN' undeclared (first use in this function)
  7. *** Error code 1
 
修改一下這個文件就能夠

cd /usr/include/mysql
root@www[/usr/include/mysql]# vi mysql.h

  在第221行
 
 
  1. ... ...
  2. enum mysql_protocol_type
  3. {
  4. MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET,
  5. MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY
  6. };
  7. /*
  8. There are three types of queries - the ones that have to go to
  9. the master, the ones that go to a slave, and the adminstrative
  10. type which must happen on the pivot connectioin
  11. */


#添加下面的4行
 
 
  1. enum mysql_rpl_type
  2. {
  3. MYSQL_RPL_MASTER, MYSQL_RPL_SLAVE, MYSQL_RPL_ADMIN
  4. };

 
二、若是出現如下錯誤:
/root/tmp/php-5.2.3/ext/mysqli/mysqli_api.c: In function 'zif_mysqli_stmt_bind_param':
/root/tmp/php-5.2.3/ext/mysqli/mysqli_api.c:144: error: 'gptr' undeclared (first use in this function)
/root/tmp/php-5.2.3/ext/mysqli/mysqli_api.c:144: error: (Each undeclared identifier is reported only once
/root/tmp/php-5.2.3/ext/mysqli/mysqli_api.c:144: error: for each function it appears in.)
/root/tmp/php-5.2.3/ext/mysqli/mysqli_api.c: In function 'zif_mysqli_stmt_execute':
/root/tmp/php-5.2.3/ext/mysqli/mysqli_api.c:603: error: 'gptr' undeclared (first use in this function)
make: *** [mysqli_api.lo] 錯誤 1
 
修改一下這個文件就能夠
vi mysqli_api.c
查找全部 gptr,有四處分別位於行14四、行150、行60三、行607,以 char* 替換
 

測試Mysqli運行情況:
Vim mysqli.php
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "dbname");
/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
printf("Host information: %s\n", $mysqli->host_info); /* close connection */ $mysqli->close(); ?>  
相關文章
相關標籤/搜索