MySQL Tutorials - Herong's Tutorial Examples - v4.46, by Herong Yang
Configuring PHP for MySQL Server Access
A tutorial example is provided on how to configure the PHP engine for MySQL server connection access. Setting, extension=php_mysql.dll, needs to be turned on in the configuration file php.ini.
To use PHP programs to access MySQL servers, of course you need to install the PHP engine on you computer first. If you need help on installing the PHP engine, please read my other tutorial book, "PHP Tutorials - Herong's Tutorial Examples" at herongyang.com/PHP.
Then you need to turn on the php_mysqli extension by editing \local\php\php.ini with:
extension=php_mysqli.dll
You may also need to add \local\php\ext to the PATH system environment variable, because php_mysqli.dll is located in the \local\php\ext directory.
When I was ready to test the configuration, I ran this script:
<?php #- MySqlTest.php # Copyright (c) 2005 HerongYang.com. All Rights Reserved. # $con = mysqli_connect('localhost','root','TopSecret'); print "MySQL server info = ".mysqli_get_server_info($con)."\n"; print "MySQL status = ".mysqli_stat($con)."\n"; mysqli_close($con); ?>
I got this this error with MySQL Server 8.0:
herong> \local\php\php -version PHP 7.3.0 (cli) (built: Dec 6 2018 01:54:19) (...) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.0-dev, Copyright (c) 1998-2018 Zend Technologies herong> \local\php\php MySqlTest.php PHP Warning: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password] in C:\herong\MySqlTest.php on line 5 ...
This error is caused by the new authentication method, caching_sha2_password, used by MySQL Server 8.0. See next tutorial on how to resolve this error.
Note that I had no problem running the same PHP script on MySQL Server 5.7:
herong> \local\php\php -version PHP 5.6.6 (cli) (built: Feb 18 2015 16:02:19) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies herong> \local\php\php MySqlTest.php MySQL server info = 5.7.10-log MySQL status = Uptime: 46148 Threads: 1 Questions: 155 Slow queries: 0 Opens: 128 Flush tables: 1 Open tables: 117 Queries per second avg: 0.003
Note that the old MySQL extension php_mysql.dll is no longer supported.
Table of Contents
MySQL Introduction and Installation
Introduction of MySQL Programs
►PHP Programs and MySQL Server
►Configuring PHP for MySQL Server Access
MySQL Authentication Method "caching_sha2_password"
mysqli_connect() and Other MySQL Functions
MySqlLoop.php - MySQL Functions Test
Perl Programs and MySQL Servers
Java Programs and MySQL Servers
Character Strings and Bit Strings
Table Column Types for Different Types of Values
Using DDL to Create Tables and Indexes
Using DML to Insert, Update and Delete Records
Using SELECT to Query Database
Window Functions for Statistical Analysis
Use Index for Better Performance
Transaction Management and Isolation Levels
Defining and Calling Stored Procedures
Variables, Loops and Cursors Used in Stored Procedures
System, User-Defined and Stored Procedure Variables
Storage Engines in MySQL Server
InnoDB Storage Engine - Primary and Secondary Indexes
Performance Tuning and Optimization
Installing MySQL Server on Linux