Specifications
Freeing Up Resources
If you are having memory problems while a script is running, you might want to use
mysql_free_result(). This has the following prototype:
int mysql_free_result(int result);
You call it with a result identifier, like this:
mysql_free_result($result);
This has the effect of freeing up the memory used to store the result. Obviously you wouldn’t
call this until you have finished working with a resultset.
Creating and Deleting Databases
To create a new MySQL database from a PHP script, you can use mysql_create_db(), and to
drop one, you can use mysql_drop_db().
These functions have the following prototypes:
int mysql_create_db(string database, [int database_connection] );
int mysql_drop_db(string database, [int database_connection] );
Both these functions take a database name and an optional connection. If no connection is sup-
plied, the last open one will be used. They will attempt to create or drop the named database.
Both functions return true on success and false on failure.
Other PHP-Database Interfaces
PHP supports libraries for connecting to a large number of databases including Oracle,
Microsoft SQL Server, mSQL, and PostgreSQL.
In general, the principles of connecting to and querying any of these databases are much the
same. The individual function names vary, and different databases have slightly different func-
tionality, but if you can connect to MySQL, you should be able to easily adapt your knowledge
to any of the others.
If you want to use a database that doesn’t have a specific library available in PHP, you can use
the generic ODBC functions. ODBC stands for Open Database Connectivity and is a standard
for connections to databases. It has the most limited functionality of any of the function sets,
for fairly obvious reasons. If you have to be compatible with everything, you can’t exploit the
special features of anything.
In addition to the libraries that come with PHP, database abstraction classes such as Metabase
are available that allow you to use the same function names for each different type of database.
Using MySQL
P
ART II
242
13 7842 CH10 3/6/01 3:36 PM Page 242