PHP Modules Tutorials - Herong's Tutorial Examples - v5.18, by Herong Yang
MySQLi Module Configuration and Database Access
This section provides a tutorial example on how to configure the PHP engine for MySQL server connection access. Setting, extension=php_mysql.dll, needs to be turned in the configuration file php.ini.
What Is MySQLi Module? - MySQLi (MySQL Improved) Module, also called MySQLi Extension, allows you to access the functionality provided by MySQL database servers. MySQLi Module was introduced in PHP 5 and is replacing the original MySQL module.
To use MySQLi module in PHP scripts, of course you need to install a MySQL server on your system first. On my local Windows system, I have a MySQL server installed in \mysql directory. If you need help on installing a MySQL server on your system, please read my other tutorial book, "MySQL Tutorials - Herong's Tutorial Examples" at herongyang.com/MySQL/
To make sure my MySQL server is running on my local system, I executed commands below to start my MySQL server and check its status:
herong> \mysql\bin\mysqld herong> \mysql\bin\mysqladmin ping mysqld is alive
MySQLi module is included in most PHP distribution packages. On some versions, you may need to enable it explicitly in the php.ini configuration file using one of the following settings:
extension=mysqli extension=mysqli.so extension=php_mysqli.dll
On Windows systems, you may need to add \php\ext to the PATH system environment variable, because php_mysqli.dll is located in the \php\ext directory.
When I was ready to test the configuration, I ran this script:
<?php
# MySqlTest.php
#- Copyright 2009-2015 (c) HerongYang.com. All Rights Reserved.
#
$con = mysqli_connect('localhost');
print "MySQL server info = ".mysqli_get_server_info($con)."\n";
print "MySQL status = ".mysqli_stat($con)."\n";
mysqli_close($con);
?>
I got this output:
herong> php MySqlTest.php MySQL server info = 5.6.28 MySQL status = Uptime: 1167 Threads: 1 Questions: 5 Slow queries... Flush tables: 1 Open tables: 0 Queries per second avg: 0.004
Cool, this confirmed that my PHP engine configured to access my MySQL server.
Table of Contents
Introduction and Installation of PHP
Managing PHP Engine and Modules on macOS
Managing PHP Engine and Modules on CentOS
DOM Module - Parsing HTML Documents
GD Module - Manipulating Images and Pictures
►MySQLi Module - Accessing MySQL Server
►MySQLi Module Configuration and Database Access
mysqli_connect() and Other MySQL Functions
MySqlLoop.php - MySQL Functions Test
OpenSSL Module - Cryptography and SSL/TLS Toolkit
PCRE Module - Perl Compatible Regular Expressions
SOAP Module - Creating and Calling Web Services
SOAP Module - Server Functions and Examples