Friday, January 29, 2010

Joomla Database Commands









Abstract Class JDatabase




Description

Database connector class
  • since: 1.0
  • abstract:




Class JObject   (Subpackage Base)
 
Abstract class JDatabase   (Subpackage Database)




Direct descendents
Class Description

ClassJDatabaseMySQL

MySQL database driver

ClassJDatabaseMySQLi

MySQLi database driver



Variable Summary
Variablestring $name
Variableresource $_cursor
Variableboolean $_debug
Variable string $_errorMsg
Variable int $_errorNum
Variable bool $_hasQuoted
Variable int $_limit
Variable array $_log
Variable string $_nameQuote
Variable string $_nullDate
Variable  int $_offset
Variable array $_quoted
Variable resource $_resource
Variable string $_sql
Variable string $_table_prefix
Variable int $_ticker
Variable boolean$_utf



Method Summary

Static method static boolean  test ( )

Constructor JDatabase __construct (array $options)

Method void addQuoted (mixed $quoted)

Method void  BeginTrans ( )

Method void  CommitTrans ( )

Method boolean connected ( )

Method void debug ( int $level )

Method void ErrorMsg ( )

Method void ErrorNo ( )

Method object  Execute (string $query)

Abstract method void explain ( )

Method void GenID( [ $foo1 = null], [ $foo2 = null] )

Abstract methodint  getAffectedRows ( )

Method void GetCol (string $query)

Abstract method string getCollation ( )

Method array getConnectors ( )

Method  string getErrorMsg  ([ $escaped = false])

Method  int getErrorNum  ( )

Abstract method
string 
getEscaped  
(string $text, [boolean $extra = false])

Method  
JDatabase  
&getInstance  
([array $options = array()])

Method 
array
getLog
()

Method  
string  
getNullDate 
( )

Abstract method  
int  
getNumRows  
([object Database $cur = null])

Method  
mixed  
GetOne  
(string $query)

Method 
string  
getPrefix  
( )

Method  
string  
getQuery  
( )

Method  
array  
GetRow  
string $query )

Abstract method  
array  
 getTableCreate
array|string $tables )

Abstract method  
array  
getTableFields  
array|string $tables, [boolean $typeonly = true] )

Abstract method  
array  
getTableList  
( )

Method  
array  
getTicker  
( )

Method  
boolean  
getUTFSupport  
( )

Abstract method  
void  
getVersion  
( )

Abstract method  
boolean  
hasUTF  
( )

Abstract method 
mixed  
insertid  
( )

Method  
void  
insertObject  
string $table, object An &$object, [string $keyName = NULL] )

Method  
bool  
isQuoted  
string $fieldName )

Abstract method  
void  
loadAssoc  
( )

Abstract method  
array  
loadAssocList  
( [string $key = ''] )

Abstract method  
void  
loadObject  
object 0 )

Abstract method  
array  
loadObjectList  
( [string $key = ''] )

Abstract method  
The  
loadResult  
( )

Abstract method  
void  
loadResultArray  
( [ $numinarray = 0] )

Abstract method  
The  
loadRow  
( )

Abstract method  
array  
loadRowList  
( [string $key = ''] )

Method 
string  
nameQuote  
string $s )

Method  
void  
PageExecute  
 $sql,  $nrows,  $page, [ $inputarr = false], [ $secs2cache = 0] )

Abstract method 
mixed 
query  
( )

Abstract method  
mixed  
queryBatch  
( [ $abort_on_error = true], [ $p_transaction_safe = false] )

Method  
string  
Quote  
string $text, [boolean $escaped = true] )

Method  
void  
replacePrefix  
string $sql, [string $prefix = '#__'] )

Method  
void  
RollbackTrans  
( )

Method  
void  
SelectLimit  
 $query,  $count, [ $offset = 0] )

Method  
void  
setQuery  
string $sql, [string $offset = 0], [string $limit = 0], [string $prefix = '#__'] )

Abstract method  
void  
setUTF  
( )

Method  
array  
splitSql  
string $queries )

Method  
string  
stderr  
( [boolean $showSQL = false] )

Abstract method  
void  
updateObject  
string $table, object &$object, string $keyName, [boolean $updateNulls = true] )



Variables




string
$name
= '' (line 33)


The database driver name






Redefined in descendants as:






resource
$_cursor
= null (line 75)


The last query cursor












boolean
$_debug
= 0 (line 82)


Debug option











string
$_errorMsg
= '' (line 54)


The database error message











int
$_errorNum
= 0 (line 47)


The database error number











bool
$_hasQuoted
= null (line 148)


Legacy compatibility
  • since: 1.5











int
$_limit
= 0 (line 89)


The limit for the query











array
$_log
= null (line 110)


A log of queries











string
$_nameQuote
= null (line 124)


Quote for named objects






Redefined in descendants as:






string
$_nullDate
= null (line 117)


The null/zero date string






Redefined in descendants as:






int
$_offset
= 0 (line 96)


The for offset for the limit











array
$_quoted
= null (line 140)


The fields that are to be quote
  • since: 1.5











resource
$_resource
= '' (line 68)


The connector resource











string
$_sql
= '' (line 40)


The query sql string











string
$_table_prefix
= '' (line 61)


The prefix used on all database tables











int
$_ticker
= 0 (line 103)


The number of queries performed by the object instance











boolean
$_utf
= 0 (line 132)


UTF-8 support
  • since: 1.5








Inherited Variables


Inherited from JObject
Variable

JObject::$_errors





Methods




Constructor __construct (line 157)


Database object constructor
  • since: 1.5
  • access: public



JDatabase

__construct

(array $options)


  • array
    $options: List of options used to configure the connection


Redefinition of:
JObject::__construct()
Class constructor, overridden in descendant classes.


Redefined in descendants as:



addQuoted (line 333)


Adds a field or array of field names to the list that are to be quoted
  • since: 1.5
  • access: public



void

addQuoted

(mixed $quoted)


  • mixed
    $quoted: Field name or array of names





BeginTrans (line 1039)


ADODB compatability function
  • since: 1.5



void

BeginTrans

()






CommitTrans (line 1057)


ADODB compatability function
  • since: 1.5



void

CommitTrans

()







connected (line 299)


Determines if the connection to the server is active.
  • since: 1.5
  • access: public



boolean

connected

()




Redefined in descendants as:



debug (line 409)


Sets the debug level on or off
  • access: public



void

debug

(int $level)


  • int
    $level: 0 = off, 1 = on





ErrorMsg (line 1066)


ADODB compatability function
  • since: 1.5



void

ErrorMsg

()






ErrorNo (line 1076)


ADODB compatability function
  • since: 1.5



void

ErrorNo

()






Execute (line 956)


ADODB compatability function
  • since: 1.5
  • access: public



object

Execute

(string $query)


  • string
    $query: SQL





explain (line 682)


Diagnostic function
  • access: public
  • abstract:



void

explain

()




Redefined in descendants as:



GenID (line 1086)


ADODB compatability function
  • since: 1.5



void

GenID

([ $foo1 = null], [ $foo2 = null])



  • $foo1


  • $foo2





getAffectedRows (line 659)


Get the affected rows by the most recent query
  • return: The number of affected rows in the previous operation
  • since: 1.0.5
  • access: public
  • abstract:



int

getAffectedRows

()




Redefined in descendants as:



GetCol (line 942)


ADODB compatability function
  • since: 1.5
  • access: public



void

GetCol

(string $query)


  • string
    $query: SQL





getCollation (line 864)


Get the database collation
  • return: Collation in use
  • access: public
  • abstract:



string

getCollation

()




Redefined in descendants as:



getConnectors (line 257)


Get the database connectors
  • return: An array of available session handlers
  • access: public



array

getConnectors

()






getErrorMsg (line 441)


Get the error message
  • return: The error message for the most recent query
  • access: public



string

getErrorMsg

([ $escaped = false])



  • $escaped





getErrorNum (line 430)


Get the error number
  • return: The error number for the most recent query
  • access: public



int

getErrorNum

()






getEscaped (line 459)


Get a database escaped string
  • abstract:
  • access: public



string

getEscaped

(string $text, [boolean $extra = false])


  • string
    $text: The string to be escaped

  • boolean
    $extra: Optional parameter to provide extra escaping



Redefined in descendants as:



getInstance (line 194)


Returns a reference to the global Database object, only creating it if it doesn't already exist.
The 'driver' entry in the parameters array specifies the database driver to be used (defaults to 'mysql' if omitted). All other parameters are database driver dependent.
  • return: A database object
  • since: 1.5



JDatabase

&getInstance

([array $options = array()])


  • array
    $options: Parameters to be passed to the database driver





getLog (line 470)


Get a database error log
  • access: public



array

getLog

()






getNullDate (line 526)


Get the database null date
  • return: Quoted null/zero date string
  • access: public



string

getNullDate

()






getNumRows (line 695)


Get the number of rows returned by the most recent query
  • return: The number of rows
  • access: public
  • abstract:



int

getNumRows

([object Database $cur = null])


  • object Database
    $cur: resource



Redefined in descendants as:



GetOne (line 1027)


ADODB compatability function
  • since: 1.5
  • access: public



mixed

GetOne

(string $query)


  • string
    $query: SQL





getPrefix (line 515)


Get the database table prefix
  • return: The database prefix
  • access: public



string

getPrefix

()






getQuery (line 634)


Get the active query
  • return: The current value of the internal SQL vairable
  • access: public



string

getQuery

()






GetRow (line 1012)


ADODB compatability function
  • since: 1.5
  • access: public



array

GetRow

(string $query)


  • string
    $query: SQL





getTableCreate (line 899)


Shows the CREATE TABLE statement that creates the given tables
  • return: A list the create SQL for the tables
  • access: public
  • abstract:



array

getTableCreate

(array|string $tables)


  • array|string
    $tables: A table name or a list of table names



Redefined in descendants as:



getTableFields (line 913)


Retrieves information about the given tables
  • return: An array of fields by table
  • access: public
  • abstract:



array

getTableFields

(array|string $tables, [boolean $typeonly = true])


  • array|string
    $tables: A table name or a list of table names

  • boolean
    $typeonly: Only return field types, default true



Redefined in descendants as:



getTableList (line 886)


List tables in a database
  • return: A list of all the tables in the database
  • access: public
  • abstract:



array

getTableList

()




Redefined in descendants as:



getTicker (line 481)


Get the total number of queries made
  • access: public



array

getTicker

()






getUTFSupport (line 420)


Get the database UTF-8 support
  • since: 1.5
  • access: public



boolean

getUTFSupport

()






getVersion (line 874)


Get the version of the database connector
  • abstract:



void

getVersion

()




Redefined in descendants as:



hasUTF (line 312)


Determines UTF support
  • since: 1.5
  • access: public
  • abstract:



boolean

hasUTF

()




Redefined in descendants as:



insertid (line 852)


Get the ID generated from the previous INSERT operation
  • access: public
  • abstract:



mixed

insertid

()




Redefined in descendants as:



insertObject (line 808)


Inserts a row into a table based on an objects properties



void

insertObject

(string $table, object An &$object, [string $keyName = NULL])


  • string
    $table: The name of the table

  • object An
    &$object: object whose properties match table fields

  • string
    $keyName: The name of the primary key. If provided the object property is updated.



Redefined in descendants as:



isQuoted (line 394)


Checks if field name needs to be quoted
  • access: public



bool

isQuoted

(string $fieldName)


  • string
    $fieldName: The field name





loadAssoc (line 727)


Fetch a result row as an associative array
  • abstract:



void

loadAssoc

()




Redefined in descendants as:



loadAssocList (line 740)


Load a associactive list of database rows
  • return: If key is empty as sequential list of returned records.
  • access: public
  • abstract:



array

loadAssocList

([string $key = ''])


  • string
    $key: The field name of a primary key



Redefined in descendants as:



loadObject (line 753)


This global function loads the first row of a query into an object
  • access: public
  • abstract:



void

loadObject

(object 0)


  • object
    0



Redefined in descendants as:



loadObjectList (line 769)


Load a list of database objects
  • return: If key is empty as sequential list of returned records. If key is not empty then the returned array is indexed by the value the database key. Returns null if the query fails.
  • access: public
  • abstract:



array

loadObjectList

([string $key = ''])


  • string
    $key: The field name of a primary key



Redefined in descendants as:



loadResult (line 707)


This method loads the first field of the first row returned by the query.
  • return: value returned in the query or null if the query failed.
  • access: public
  • abstract:



The

loadResult

()




Redefined in descendants as:



loadResultArray (line 717)


Load an array of single field results into an array
  • abstract:



void

loadResultArray

( $numinarray)



  • $numinarray



Redefined in descendants as:



loadRow (line 781)


Load the first row returned by the query
  • return: first row of the query.
  • access: public
  • abstract:



The

loadRow

()




Redefined in descendants as:



loadRowList (line 797)


Load a list of database rows (numeric column indexing)
If key is not empty then the returned array is indexed by the value the database key. Returns null if the query fails.
  • access: public
  • abstract:



array

loadRowList

([string $key = ''])


  • string
    $key: The field name of a primary key



Redefined in descendants as:



nameQuote (line 493)


Quote an identifier name (field, table, etc)
  • return: The quoted name
  • access: public



string

nameQuote

(string $s)


  • string
    $s: The name





PageExecute (line 996)


ADODB compatability function
  • since: 1.5
  • access: public



void

PageExecute

( $sql,  $nrows,  $page, [ $inputarr = false],  $secs2cache)



  • $sql


  • $nrows


  • $page


  • $inputarr


  • $secs2cache





query (line 646)


Execute the query
  • return: A database resource if successful, FALSE if not.
  • access: public
  • abstract:



mixed

query

()




Redefined in descendants as:



queryBatch (line 671)


Execute a batch query
  • return: A database resource if successful, FALSE if not.
  • access: public
  • abstract:



mixed

queryBatch

([ $abort_on_error = true], [ $p_transaction_safe = false])



  • $abort_on_error


  • $p_transaction_safe



Redefined in descendants as:



Quote (line 930)


Get a quoted database escaped string
  • access: public



string

Quote

(string $text, [boolean $escaped = true])


  • string
    $text: A string

  • boolean
    $escaped: Default true to escape string, false to leave the string unchanged





replacePrefix (line 558)


This function replaces a string identifier $prefix with the string held is the _table_prefix class variable.
  • access: public



void

replacePrefix

(string $sql, [string $prefix = '#__'])


  • string
    $sql: The SQL query

  • string
    $prefix: The common table prefix





RollbackTrans (line 1048)


ADODB compatability function
  • since: 1.5



void

RollbackTrans

()






SelectLimit (line 981)


ADODB compatability function
  • since: 1.5
  • access: public



void

SelectLimit

( $query,  $count,  $offset)



  • $query


  • $count


  • $offset





setQuery (line 543)


Sets the SQL query string for later execution.
This function replaces a string identifier $prefix with the string held is the _table_prefix class variable.
  • access: public



void

setQuery

(string $sql, string $offset, string $limit, [string $prefix = '#__'])


  • string
    $sql: The SQL query

  • string
    $offset: The offset to start selection

  • string
    $limit: The number of results to return

  • string
    $prefix: The common table prefix





setUTF (line 323)


Custom settings for UTF support
  • since: 1.5
  • access: public
  • abstract:



void

setUTF

()




Redefined in descendants as:



splitSql (line 350)


Splits a string of queries into an array of individual queries
  • return: queries
  • access: public



array

splitSql

(string $queries)


  • string
    $queries: The queries to split





stderr (line 834)


Print out an error statement
  • return: A standised error message



string

stderr

([boolean $showSQL = false])


  • boolean
    $showSQL: If TRUE, displays the last SQL statement sent to the database





test (line 287)


Test to see if the MySQLi connector is available
  • return: True on success, false otherwise.
  • access: public



boolean

test

()




Redefined in descendants as:



updateObject (line 823)


Update an object in the database
  • access: public
  • abstract:



void

updateObject

(string $table, object &$object, string $keyName, [boolean $updateNulls = true])


  • string
    $table

  • object
    &$object

  • string
    $keyName

  • boolean
    $updateNulls



Redefined in descendants as:

Inherited Methods



Inherited From JObject

JObject::JObject()


JObject::__construct()


JObject::get()


JObject::getError()


JObject::getErrors()


JObject::getProperties()


JObject::getPublicProperties()


JObject::set()


JObject::setError()


JObject::setProperties()


JObject::toString()





Copyright

Some parts of this documentation was taken from http://api.joomla.org/Joomla-Framework/Database/JDatabase.html (© 2005 - 2008 Open Source Matters Inc) and is used with
permission granted by the Joomla! Electronic Documentation License v 1.0.


Joomla! Electronic Documentation License v 1.0



Definitions


To "Propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except displaying or modifying a private copy.
The "Work" is any copyrightable material licensed under the terms of this license or any material based on such material. The "Author" means all the people or entities who have the legal right to grant permission to Propagate the Work or parts of the Work. Each licensee is addressed as "you".
"Electronic Media" means any device, medium or technology used to store, record, display, transmit or modify electronic information, including websites, compact discs, digital video discs, hard disks, magnetic media, and computer networks. "Electronic Media" does not include, for example, books printed on paper.
"Grantback License" means a non-exclusive, perpetual, worldwide, royalty-free license to Propagate the Work in any medium and by any means.
"Copyleft License" means a license to Propagate the Work under the terms of this license or any future version of the Joomla Electronic Documentation License published by Open Source Matters, Incorporated.
The "Source Form" of a work means the preferred form of the Work for making modifications to it. For text works, this could be plain ASCII text format.

Conditional Permissions


If you grant a Grantback License to the Author and a Copyleft License to anybody who comes into possession of the Work, you may Propagate the Work via Electronic Media for any purpose, including commercial purposes.
You must make available at no charge to anybody to whom you distribute the Work a version of the Work in Source Form. Such availability must be via either (1) the same means and method with which you distribute the Work or (2) simple download over the internet. You may not condition providing the Source Form of the Work on anything other than acceptance of this license.
You must provide a copy of this license, notice that it applies to the Work, and information needed to acquire the Source Form to anybody to whom you distribute the Work.
You must preserve the Author's copyright notices in the Work and display them as prominently as you display your own.

Reservations of Rights


Nothing in this license grants you or anybody else any right to Propagate the Work in any medium or through any means other than Electronic Media.
Nothing in this license grants you or anybody else any right to do anything that requires permission under trademark law. Specifically, nothing in this license grants you permission to represent that the Work is "official" or in any way endorsed or sanctioned by the Authors.

CrossLoop

About Me

My Photo
Jack Briner
I'm a Texan who is living in South Carolina. I love living in Charleston with its history and proximity to the water. I'm married to a Lutheran pastor. We have two teenagers and two dogs.
View my complete profile

Some of my sites