Class: eDQuery

Source Location: Program_Root/eDFramework/eDQuery.php

Class Overview [line 30]

eDUtilities
   |
   --eDQuery

MySQL Select Query Generator

Author(s):

Version:

Copyright:

Variables

Methods


Inherited Methods

Class: eDUtilities

eDUtilities::introspection()
Dumps objects and arrays.
eDUtilities::is_defined()
Is the string $str_ defined From what I know, yet no PHP function allows to test if a string is defined.
eDUtilities::setTrace()
Sets the TRACE flag, mode and format
eDUtilities::trace()
Print a string and flushes the output buffer


Class Details

MySQL Select Query Generator

This script centralizes all the code required to build and launch a Select query aindex.phpgainst a MySQL db eDQuery can build all kind of select queries but assumes that the most encoutered one are build on the following model: SELECT field1 [, field2] FROM database1.table1 [, database1.table2] WHERE field3 = 'value' This would be translated into the following using eDQuery: $myQuery = new eDQuery('database1', array('table1', [table2]), array('field1','field2'), array('field3' => "'value'"), null, $debug ); $arr_results = $myQuery->getRecords(); Another version is under construction supporting all types of PHP supported databases

Why and When should I use eDQuery? ---------------------------------------------------- First because it will centralize into one script only the code to access your MySQL db. It gives more independancy to your script towards your db and all improvments made to eDQuery will be available to all your scripts without having to rewrite your code. Just imagine that you'd like to use an Oracle db instead of a MySQL one, you'd only need to make minor changes to this script (mainly in the runQuery() and getRecords() functions. eDQuery also provides useful functions like getValue to easily find a field value in the array of your records So, when to use it? As often as possible of course :)

Tags:

[ Top ]


Class Variables

$arr_from = array()

[line 43]

eDQuery::$arr_from

{ Description }

Type: mixed

Overrides:

[ Top ]

$arr_rec = array()

[line 85]

eDQuery::$arr_rec

{ Description }

Type: mixed

Overrides:

[ Top ]

$arr_select = array()

[line 50]

eDQuery::$arr_select

{ Description }

Type: mixed

Overrides:

[ Top ]

$connId =  0

[line 99]

eDQuery::$connId

{ Description }

Type: mixed

Overrides:

[ Top ]

$dbName =  ''

[line 36]

eDQuery::$dbName

{ Description }

Type: mixed

Overrides:

[ Top ]

$orderBy =  ''

[line 64]

eDQuery::$orderBy

{ Description }

Type: mixed

Overrides:

[ Top ]

$qry_ =  ''

[line 71]

eDQuery::$qry_

{ Description }

Type: mixed

Overrides:

[ Top ]

$rst_ =  ''

[line 78]

eDQuery::$rst_

{ Description }

Type: mixed

Overrides:

[ Top ]

$traceMode =  'log'

[line 92]

eDQuery::$traceMode

{ Description }

Type: mixed

Overrides:

[ Top ]

$where =  ''

[line 57]

eDQuery::$where

{ Description }

Type: mixed

Overrides:

[ Top ]


Class Methods

eDQuery

eDQuery eDQuery( [mixed $connId = null], string $dbName, array $arr_from, array $arr_select, [mixed $where = ''], [string $orderBy = ''], [string $mode = 'extended'], [boolean $traceEnabled = FALSE$str_extranull], array $arr_where, string $extra)

[line 120]

Class Constructor

Today the constructor launches the construction and the execution of the query (extended mode) but this can be moved away to stay under the responsability of the script calling eDQuery

Change Log 15/08/2003 BPO SFFRxxxxxx eDFramework - eDQuery EXTRA Statements

Parameters:

  • string $dbName - name of the db against which the query will be launched
  • array $arr_from - array containing the list of table to query, ex: array('system', 'employee')
  • array $arr_select - array containing the list of fields to retrieve, ex: array('systemid', 'employeeid')
  • array $arr_where - array describing the where clause, ex: array('systemid' => "'1'") or array("systemid > '1'" => '') for clause not based on = operators
  • string $orderBy - name of the field(s) to use to order the results of the query
  • string $mode - only build the query in normal mode, build and run the query in extended mode
  • boolean $traceEnabled - enter function in debug mode (enables outputs) or not
  • string $extra - extra SQL instructions to add to the query, to be used for other than SELECT, WHERE, ORDER BY instructions

[ Top ]

buildQuery

void buildQuery( mixed $str_extra)

[line 195]

Build the query

Change Log 15/08/2003 BPO SFFR#xxxxxx eDFramework - eDQuery EXTRA Statements 6/01/2003 BPO SFFR#663119 eDFramework - eDQuery WHERE Statement 31/12/2002 BPO SFFR#591993 eDFramework - eDQuery From Statement

Parameters:

[ Top ]

connect

void connect( [mixed $dbHost = 'localhost'], [mixed $dbUser = 'root'], [mixed $dbPassword = ''])

[line 171]

Connect the host database

{ Description }

Tags:

  • since - eDQuery v2.0

Parameters:

[ Top ]

getQuery

string getQuery( )

[line 275]

Returns the generated query

{ Description }

Tags:

  • return - the generated SQL query

Parameters:

[ Top ]

getRecord

array getRecord( string $searchKey, string $searchValue)

[line 334]

Finds a record within the array of records

Example of use: $arr_foundRecord = getRecord('employee', 'Paul')

Change Log 31/12/2002 BPO SFFR#592005 eDFramework - eDQuery Search function

Tags:

  • return - the FIRST record where 'searchValue' has been found

Parameters:

  • string $searchKey - the name of field where to search
  • string $searchValue - the field value to find

[ Top ]

getRecords

array getRecords( [mixed $format = 'array'])

[line 293]

Returns two dimensional array of array containing one array per record

results can be retrieved thanks to the following code in the calling script $arr_rec = $myeDQuery->getRecord(); foreach ($arr_rec as $key => $value) { echo $value['fieldname']; }

ChangeLog: 30/12/2002 BPO SFFR#659958 eDFramework - eDQuery getRecords Mode

Tags:

  • return - the array of associative array, each representing a record returned by the query

Parameters:

[ Top ]

getValue

string getValue( string $searchKey, string $searchValue, string $returnKey)

[line 356]

Finds a key within a record within the array of records

Example of use: $findMe = getValue('employee', 'Paul', 'location')

Change Log 31/12/2002 BPO SFFR#592005 eDFramework - eDQuery Search function

Tags:

  • return - the value of field 'returnKey' extracted from the record where 'searchValue' has first been found

Parameters:

  • string $searchKey - the name of field where to search
  • string $searchValue - the field value to find
  • string $returnKey - the field from which to return the value once a record is found

[ Top ]

runQuery

void runQuery( mixed $connId, mixed $dbName)

[line 241]

Run the query

Change Log: 30/12/2002 BPO SFBG#621819 eDFramework - eDQuery Debug Messages 16/12/2002 BPO SFFR#591985 eDFramework - eDQuery MySQL Connect

Parameters:

[ Top ]


Documentation generated on Wed, 10 Dec 2003 21:47:48 +0100 by phpDocumentor 1.2.2