Instalação

A extensão mysqli foi introduzida com o PHP versão 5.0.0. O MySQL Native Driver foi incluído no PHP na versão 5.3.0.

Instalação no Linux

As distribuições comuns do Unix incluem versões binárias do PHP que podem ser instaladas. Embora estas versões binárias sejam tipicamente construídas com suporte às extensões MySQL, as próprias bibliotecas das extensões podem precisar de pacote adicional para instalação. Verifique o gerenciador de pacote que vem com sua distribuição escolhida para disponibilidade.

Por exemplo, no Ubuntu o pacote php5-mysql instala as extensões do PHP ext/mysql, ext/mysqli e pdo_mysql. No CentOS, o pacote php-mysql também instala estas três extensões PHP.

Alternativamente, pode-se compilar esta extensão. Construir o PHP a partir do código-fonte permite que se especifique as extensões MySQL que se deseja usar, bem como pode-se escolher a biblioteca cliente para cada extensão.

O MySQL Native Driver é a opção de biblioteca cliente recomendada, pois resulta em melhor desempenho e dá acesso a recursos não disponíveis ao usar a Biblioteca Cliente MySQL. Consulte a página O que é o Driver Nativo do MySQL? para uma visão breve das vantagens do Driver Nativo MySQL.

/path/to/mysql_config representa a localização do programa mysql_config que vem com o Servidor MySQL.

Matriz de suporte ao mysqli em tempo de compilação
Versão do PHP Padrão Opções de Configuração: mysqlnd Opções de Configuração: libmysqlclient Registro de Alterações
5.4.x e acima mysqlnd --with-mysqli --with-mysqli=/path/to/mysql_config mysqlnd é o padrão
5.3.x libmysqlclient --with-mysqli=mysqlnd --with-mysqli=/path/to/mysql_config mysqlnd é suportada
5.0.x, 5.1.x, 5.2.x libmysqlclient Não Disponível --with-mysqli=/path/to/mysql_config mysqlnd não é suportada

Observe que é possível misturar livremente extensões MySQL e bibliotecas cliente. Por exemplo, é possível habilitar a extensão MySQL para usar a biblioteca cliente MySQL (libmysqlclient), enquanto configura a extensão mysqli para usar o driver nativo MySQL. No entanto, todas as permutações de extensão e biblioteca cliente são possíveis.

Instalação em Sistemas Windows

No Windows, a DLL php_mysqli.dll deve ser habilitada no php.ini.

Como em qualquer habilitação de extensão PHP (como php_mysqli.dll), a diretiva PHP extension_dir seve ser definida para o diretório onde as extensões do PHP estão localizadas. Consulte também as Instruções de Instalação Manual no Windows. Um exemplo de valor para extension_dir é c:\php\ext.

Nota:

Se ao iniciar o servidor web um erro parecido com este ocorrer: "Unable to load dynamic library './php_mysqli.dll'", é porque php_mysqli.dll não pôde ser encontrada no sistema.

add a note add a note

User Contributed Notes 4 notes

up
-13
David dot Kit dot Friedman at gmail dot com
14 years ago
>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.
up
-19
Mark F
13 years ago
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
up
-27
bansi
4 years ago
In Windows 10 if mysqli is not working in PHP 7.3 you should add PHP directory to the PATH and restart your web server. This behavior was not there in PHP 7.0.27.
up
-56
josh dot ribakoff at gmail dot com
14 years ago
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.
To Top