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 system first. If you need help on installing the PHP engine, please read my other tutorial book, "PHP Tutorials - Herong's Tutorial Examples".

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) 2015, 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 output:

C:\herong>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

C:\herong>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

Cool, this confirmed that my PHP engine is configured to access my MySQL server.

Last update: 2015.

Table of Contents

 About This Book

 Introduction of SQL

 MySQL Introduction and Installation

 Introduction of MySQL Programs

 Perl Programs and MySQL Servers

PHP Programs and MySQL Servers

Configuring PHP for MySQL Server Access

 mysqli_connect() and Other MySQL Functions

 MySqlLoop.php - MySQL Functions Test

 Java Programs and MySQL Servers

 Datatypes and Data Literals

 Operations and Expressions

 Character Strings and Bit Strings

 Commonly Used Functions

 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

 Transaction Management and Isolation Levels

 Locks Used in MySQL

 Defining and Calling Stored Procedures

 Variables, Loops and Cursors Used in Stored Procedures

 Outdated Tutorials

 References

 PDF Printing Version