w3resource logo


PHP Tutorial

Installing and configuring PHP for MySQL functions

Secondary Nav

Requirements

You must have PHP installed with MySQL support enabled for executing MySQL functions is PHP.

Installation on Linux

In PHP 5.3 and above, MySQL Native Driver is used by default for MySQL database extensions. So, MySQL Client Library (libmysql) is no longer required.
The extensions mysql, mysqli, and PHP_PDO_MYSQL are all enabled by default in PHP 5.3.0 and above.

If you are using a slightly dated PHP version (any of PHP 5, 5.1, 5.2), MySQL is not enabled by default. You have to use "--with-mysql=/path_to_mysql" option is enable MySQL support.

Installation on Windows

In PHP 5.3 and above, it is same as installing on Linux. For PHP 5, 5.1 or 5.2, MySQL is not enabled by default. So you have to open php.ini file and un comment extension=php_mysql.dll.

Runtime configuration

Name Description Type Default Changeable
mysql.allow_persistent Determines if persistent connections are allowed to MySQL. integer "1" PHP_INI_SYSTEM
mysql.max_persistent Determines the maximum number of persistent connections per process allowed to MySQL. integer "-1" PHP_INI_SYSTEM
mysql.max_links Determines the maximum number of persistent connections per process, including persistent connections, allowed to MySQL. integer "-1" PHP_INI_SYSTEM
mysql.trace_mode If enabled, warnings for table/index scans, non free result sets, and SQL-Errors are displayed. boolean "0" PHP_INI_ALL
mysql.default_port If no other ports are specified, this determines the default TCP post to be used to connect to MySQL Server. string NULL PHP_INI_ALL
mysql.default_socket If no other socket name is specified, this determines the default socket name to be used to connect to MySQL Server. string NULL PHP_INI_ALL
mysql.default_host If no other host is specified, this determines the default host to be used to connect to MySQL Server. This is not applicable in SQL SAFE MODE. string NULL PHP_INI_ALL
mysql.default_user If no other user is specified, this determines the default user to be used to connect to MySQL Server. This is not applicable in SQL SAFE MODE. string NULL PHP_INI_ALL
mysql.default_password If no other password is specified, this determines the default password to be used to connect to MySQL Server. This is not applicable in SQL SAFE MODE. string NULL PHP_INI_ALL
mysql.connect_timeout Specifies the connection timeout is seconds. In Linux, this also specifies the time to wait for the first answer from the DataBase Server. integer "60" PHP_INI_ALL

Resource types

There are two resource type used in MySQL module.

1. Link identifier for the database connection.

2. A resource which contains the result of a MySQL query.

PHP MySQL sample database for examples 

Purpose

Here we will discuss about the database we are going to use for examples of MySQL functions, so that you too can create it on your own computer and  try examples discussed in the subsequent pages.

1. We have created a blank database (without any records) in MySQL using MySQL Administrator. 

2. This is the structure of tables used in out MySQL examples

mysql example tables

3. MySQL user name we have used for all these examples is root. This is the default administrative user we created during the installation of MySQL. Password for the user root is mypass.

You also must have Apache (or any other standard web server) up and running for trying our examples.

We encourage you create a similar database in your own Computer and use our codes for each function to better understand the subject.

See also

PHP Function Reference



Join our Question Answer community to learn and share your programming knowledge.