downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

実行時設定> <要件
[edit] Last updated: Fri, 25 May 2012

view this page in

インストール手順

mysqli 拡張モジュールが使えるようになったのは PHP バージョン 5.0.0 以降です。また、MySQL Native Driver が PHP に含まれるようになったのはバージョン 5.3.0 以降です。

Linux でのインストール

一般的な Unix ディストリビューションには、バイナリ版の PHP がインストールされています。 これらのバイナリ版は、通常は MySQL 拡張モジュールに対応したものになっています。 しかし、拡張モジュールライブラリ自身を別パッケージでインストールする必要があるでしょう。 使用しているディストリビューションのパッケージマネージャで確認してみましょう。

もしご利用の Unix ディストリビューションの提供するバイナリパッケージに mysqli 拡張モジュールが含まれていない場合は、 PHP をソースコードからビルドしなければなりません。 PHP をソースからビルドすれば、使いたい MySQL 拡張モジュールを指定したり 各拡張モジュールが使用するクライアントライブラリを選択したりすることができます。

MySQL Native Driver を使うことを推奨します。 そのほうがパフォーマンスが向上し、MySQL Client Library を使用した場合には使えない機能も使用することができます。 PHP の MySQL Native Driver とは? に、MySQL Native Driver の利点が簡単にまとめられています。

/path/to/mysql_config は、MySQL Server に含まれる mysql_config プログラムの場所を表します。

mysqli のコンパイル時のサポート表
PHP バージョン デフォルト 設定オプション: mysqlnd 設定オプション: libmysql 変更履歴
5.0.x, 5.1.x, 5.2.x libmysql 利用できません --with-mysqli=/path/to/mysql_config  
5.3.x libmysql --with-mysqli=mysqlnd --with-mysqli=/path/to/mysql_config mysqlnd が使えるようになりました。
5.4.x mysqlnd --with-mysqli --with-mysqli=/path/to/mysql_config mysqlnd がデフォルトになりました。

MySQL 拡張モジュールとクライアントライブラリの組み合わせは自由であることに注意しましょう。 たとえば、MySQL 拡張モジュールは MySQL Client Library (libmysql) を使うようにして有効にし、 一方 mysqli 拡張モジュールは MySQL Native Driver を使うようにするということも可能です。 しかし、それ以外にも拡張モジュールとクライアントライブラリのすべての組み合わせが使用可能です。

次の例は、MySQL 拡張モジュールを MySQL Client Library を使うようにビルドし、一方 mysqli と PDO MYSQL 拡張モジュールでは MySQL Native Driver を使うようにするものです。

./configure --with-mysql=/usr/bin/mysql_config  \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd
[other options]

Windows システムでのインストール

Windows の場合、PHP のインストールにはたいていバイナリインストーラを使用します。

PHP 5.0, 5.1, 5.2

PHP をインストールしたら、mysqli を有効にしてクライアントライブラリを指定するためにいくつかの設定が必要です。

mysqli 拡張モジュールはデフォルトでは有効になりません。そこで、 php_mysqli.dll DLL を php.ini の中で有効化しなければなりません。有効化するには、まず php.ini を探し (通常は c:\php にあります)、 そして extension=php_mysqli.dll という行の最初にあるコメント (セミコロン) を削除します。この行は [PHP_MYSQLI] というセクションにあります。

また、MySQL Client Library を mysqli で使いたい場合は、PHP からクライアントライブラリのファイルにアクセスできるようにしなければなりません。 MySQL Client Library は libmysql.dll という名前のファイルで、これは Windows 版の PHP に含まれています。 このファイルを Windows の環境変数 PATH で指定された場所に置けば読み込めるようになります。 FAQ の "Windows で PHP のディレクトリを PATH に追加するにはどうすればいいのですか?" に、その方法が説明されています。 libmysql.dll を Windows のシステムディレクトリ (通常は c:\Windows\system) にコピーしても動作します。 システムディレクトリは、デフォルトでシステムの PATH に含まれているからです。 しかし、これはできるだけ避けるようにしましょう。

その他の PHP 拡張モジュール (php_mysqli.dll など) を有効にするときと同様、PHP のディレクティブ extension_dir を設定して PHP 拡張モジュールのある場所を指定する必要があります。 Windows での手動インストールの手順 も参照ください。PHP 5 の extension_dir の値は、たとえば c:\php\ext のようになります。

注意:

ウェブサーバーの起動時に "Unable to load dynamic library './php_mysqli.dll'" のようなエラーが出たら、それは php_mysqli.dlllibmysql.dll をシステムが見つけられないことが原因です。

PHP 5.3.0+

Windows の PHP バージョン 5.3 以降では、 mysqli 拡張モジュールはデフォルトで有効になっており、 また MySQL Native Driver を使うようになっています。つまり、 libmysql.dll にアクセスできるようにする必要はないということです。



実行時設定> <要件
[edit] Last updated: Fri, 25 May 2012
 
add a note add a note User Contributed Notes インストール手順
Mark F 13-Mar-2011 07:09
Just to note with regards to SSL and compression. MySQLnd and thus extensions using mysqlnd such as mysqli... now supports SSL and compression. Both have been supported inside mysqlnd since PHP 5.3.3 - http://www.php.net/manual/en/mysqlnd.overview.php
arekm 23-Aug-2010 11:49
"using the MySQL Native Driver results in improved performance and gives access to features not available when using the MySQL Client Library"

Of course there are also disadvantages:
- no SSL support (a nightmare!)
- no mysql < 4.1 support

So some people cannot use mysqlnd :(
josh dot ribakoff at gmail dot com 10-Nov-2009 03:21
I kept getting configure errors:

/tmp/cc4f2PKd.o: In function `main':
/usr/src/php-5.3.0/configure:14287: undefined reference to `yp_get_default_domain'
collect2: ld returned 1 exit status
configure: failed program was:
#line 14270 "configure"
#include "confdefs.h"

The solution was to configure with mysql native driver as outlined on this page.
David dot Kit dot Friedman at gmail dot com 19-Aug-2009 10:04
>On Windows, PHP is most commonly installed using the binary installer. Once PHP has been installed, some >configuration is required to enable mysqli and specify the client library you want it to use.

Basically, if you want to add extensions you can double-click again on the installer file. The installer will find the already installed PHP and will ask if you want to change the installation.

When you go through the prompts it will take you back to the list of extensions and you can pick which extensions you want to add.

For the mysqli extension the installer also edited php.ini so that the extension was enabled:

[PHP_MYSQLI]
extension=php_mysqli.dll

the installer added those lines to the end of the file.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites