PHP MySQL Functions
PHP MySQL Introduction
The MySQL functions allows you to access MySQL database servers.
Installation
For the MySQL functions to be available, you must compile PHP with MySQL
support.
For compiling, use --with-mysql=DIR (the optional DIR points to the MySQL directory).
Note: For full functionality of MySQL
versions greater than 4.1., use the MySQLi extension instead. If you would like to install
both the mysql extension and the mysqli extension you should use the same client
library to avoid any conflicts.
Installation on Linux Systems
PHP 5+: MySQL and the MySQL library is not enabled by default. Use the
--with-mysql=DIR configure option to include MySQL
support and download headers and libraries from
www.mysql.com.
Installation on Windows Systems
PHP 5+: MySQL is not enabled by default, so the php_mysql.dll must be enabled inside of php.ini. Also, PHP needs access to the MySQL
client library. A file named libmysql.dll is included in the Windows PHP
distribution, and in order for PHP to talk to MySQL this file needs to be
available to the Windows systems PATH.
To enable any PHP extension, the PHP extension_dir setting (in the php.ini
file) should be set to the directory where the PHP extensions are
located. An example extension_dir value is c:\php\ext.
Note: If you get the following error when starting the web server: "Unable to load dynamic library './php_mysql.dll'", this is because
php_mysql.dll or libmysql.dll cannot be found by the system.
Runtime Configuration
The behavior of the MySQL functions is affected by settings in the php.ini
file.
MySQL configuration options:
Name |
Default |
Description |
Changeable |
mysql.allow_persistent |
"1" |
Whether or not to allow persistent connections |
PHP_INI_SYSTEM |
mysql.max_persistent |
"-1" |
The maximum number of persistent connections per
process |
PHP_INI_SYSTEM |
mysql.max_links |
"-1" |
The maximum number of connections per process
(persistent connections included) |
PHP_INI_SYSTEM |
mysql.trace_mode |
"0" |
Trace mode. When set to "1", warnings and SQL-errors will be displayed.
Available since PHP 4.3 |
PHP_INI_ALL |
mysql.default_port |
NULL |
The default TCP port number to use |
PHP_INI_ALL |
mysql.default_socket |
NULL |
The default socket name to use. Available since PHP
4.0.1 |
PHP_INI_ALL |
mysql.default_host |
NULL |
The default server host to use (doesn't apply in SQL safe
mode) |
PHP_INI_ALL |
mysql.default_user |
NULL |
The default user name to use (doesn't apply in SQL safe
mode) |
PHP_INI_ALL |
mysql.default_password |
NULL |
The default password to use (doesn't apply in SQL safe mode) |
PHP_INI_ALL |
mysql.connect_timeout |
"60" |
Connection timeout in seconds |
PHP_INI_ALL |
Resource Types
There are two resource types used in the MySQL extension. The first one is the
link_identifier for a database connection, the second is a resource which holds the
result of a query.
Note: Most MySQL functions accept link_identifier as the last optional
parameter. If it is not provided, the last opened connection is used.
PHP MySQL Functions
PHP: indicates the earliest version of PHP that supports the
function.
PHP MySQL Constants
Since PHP 4.3 it has been possible to specify additional flags for the mysql_connect() and mysql_pconnect() functions:
PHP: indicates the earliest version of PHP that supports the
constant.
Constant |
Description |
PHP |
MYSQL_CLIENT_COMPRESS |
Use compression protocol |
4.3 |
MYSQL_CLIENT_IGNORE_SPACE |
Allow space after function names |
4.3 |
MYSQL_CLIENT_INTERACTIVE |
Allow interactive timeout seconds
of inactivity before closing the connection |
4.3 |
MYSQL_CLIENT_SSL |
Use SSL encryption (only available with
version 4+ of the MySQL client library) |
4.3 |
The mysql_fetch_array() function uses a constant for the different types of
result arrays. The following constants are defined:
Constant |
Description |
PHP |
MYSQL_ASSOC |
Columns are returned into the array with the fieldname as
the array index |
|
MYSQL_BOTH |
Columns are returned into the array having both a numerical
index and the fieldname as the array index |
|
MYSQL_NUM |
Columns are returned into the array having a numerical
index (index starts at 0) |
|
|
|
|
See why there are 20,000+ Ektron integrations worldwide.
Request an INSTANT DEMO or download a FREE TRIAL today. |
|
|
|