Class: MySQL_Query extends Query
- Package: saf.Database
- Author: John Luxford <lux@simian.ca>
- Copyright: Copyright (C) 2001-2003, Simian Systems Inc.
- License: http://www.sitellite.org/index/license Simian Open Software License
- Version: 1.6, 2002-07-09, $Id: MySQL.php,v 1.4 2007/09/01 17:02:17 lux Exp $
- Access: public
MySQL_Driver is the Database driver for the MySQL database system.
MySQL_Query provides all of the MySQL-specific functionality
for Query objects. It is accessed through the Database class API.
New in 1.2:
- Updated to work with saf.Database 2.0
New in 1.4:
- Fixed a bug that caused the error () and errno () methods to return
blank strings.
New in 1.6:
- Removed the fetchXML() method, since it isn't necessary and simply inherits
from the base Query class.
Usage Example
<?php
$q = new MySQL_Query ("select * from table");
if ($q->execute ()) {
while ($row = $q->fetch ()) {
// do something with $row
}
$q->free ();
} else {
// query failed
}
?>
Return to Top
Properties
$connection = ''
The resource ID for the database connection to be queried.
$path
Path to the Berkeley Database.
$mode
Mode to use when opening the database (corresponds to
the modes available to the dba_open () function.
$handler
The database implementation used (db2, db3, gdbm, etc.).
$persistent
Whether or not to use persistence when connecting to the database.
$transactions = 0
Boolean value denoting whether to enable transactions in the
current database.
$driver
Contains the name of the database driver being used.
$host
Contains the name of the database host.
$name
Contains the name of the database being used.
$user
Contains the username used to connect to the current database.
$pass
Contains the password used to connect to the current database.
$dbd
Contains the loaded database driver.
$error
Contains the error message if an error occurs here. For most
uses however, you will want to use the error() method of the Query
object instead.
$sql = ''
Contains the SQL query to be executed.
$rows
Contains the number of rows returned by the previous fetch() call.
$lastid
Contains the lastid() of the last insert query sent to the execute()
method.
$tables = false
Contains a list of tables in the database. Set by getTables().
$pearEmu = false
$sequenceFormat = '%s_seq'
$fetchMode = DB_FETCHMODE_OBJECT
$result = ''
Contains the result identifier for the current execution.
$field = ''
Currently unused.
$_fetchModeFunctions = array (
DB_FETCHMODE_ASSOC => 'mysql_fetch_array',
DB_FETCHMODE_OBJECT => 'mysql_fetch_object',
)
Return to Top
Methods
MySQL_Query ($sql = '', &$conn, $cache = 0)
Constructor method.
$sql is the SQL query you wish to execute with this object.
$conn is the database connection resource to be queried.
execute ()
- Access: public
- Return: resource
Executes the current SQL query.
$values is an array of values to substitute. The syntax for denoting
bind_values in the SQL query is a double-questionmark (??).
Returns the new SQL query. Note: does not modify the actual $sql property.
field ($num = 0)
- Access: public
- Return: string
Returns the name of the specified column in the table currently being queried.
$num is the column number. Note: Some database systems begin with
column 0, while others with 1.
rows ()
- Access: public
- Return: integer
Returns the number of rows affected or found by the current query.
lastid ()
- Access: public
- Return: integer
Returns the row ID generated by the database during the previous
SQL insert query.
fetch ($offset = 0, $limit = 0)
- Access: public
- Return: object
Returns the next row of data from the current query, always in the
form of an object, with each column as its properties.
free ()
Tells the database system to let go of its data from the previous
query.
begin ()
Issues a mysql "begin" statement, beginning a transaction.
commit ()
Issues a mysql "commit" statement, committing the current transaction.
rollback ()
Issues a mysql "rollback" statement, rolling back the current transaction.
errno ()
- Access: public
- Return: integer
Returns the database error number in case of error.
error ()
- Access: public
- Return: string
Returns the database error message in case of error.
Return to Top