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 = ''

  • Access: public

The resource ID for the database connection to be queried.


$path

  • Access: public

Path to the Berkeley Database.


$mode

  • Access: public

Mode to use when opening the database (corresponds to
the modes available to the dba_open () function.


$handler

  • Access: public

The database implementation used (db2, db3, gdbm, etc.).


$persistent

  • Access: public

Whether or not to use persistence when connecting to the database.


$transactions = 0

  • Access: public

Boolean value denoting whether to enable transactions in the
current database.


$driver

  • Access: public

Contains the name of the database driver being used.


$host

  • Access: public

Contains the name of the database host.


$name

  • Access: public

Contains the name of the database being used.


$user

  • Access: public

Contains the username used to connect to the current database.


$pass

  • Access: public

Contains the password used to connect to the current database.


$dbd

  • Access: private

Contains the loaded database driver.


$error

  • Access: public

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 = ''

  • Access: public

Contains the SQL query to be executed.


$rows

  • Access: public

Contains the number of rows returned by the previous fetch() call.


$lastid

  • Access: public

Contains the lastid() of the last insert query sent to the execute()
method.


$tables = false

  • Access: public

Contains a list of tables in the database. Set by getTables().


$pearEmu = false


$sequenceFormat = '%s_seq'


$fetchMode = DB_FETCHMODE_OBJECT


$result = ''

  • Access: public

Contains the result identifier for the current execution.


$field = ''

  • Access: public

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)

  • Access: public

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 ()

  • Access: public

Tells the database system to let go of its data from the previous
query.


begin ()

  • Access: public

Issues a mysql "begin" statement, beginning a transaction.


commit ()

  • Access: public

Issues a mysql "commit" statement, committing the current transaction.


rollback ()

  • Access: public

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

Copyright © 2008 Sitellite CMS Project

Powered by Sitellite 5.0 Content Management System