Source for file mysql.php
Documentation is available at mysql.php
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2004 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@backendmedia.com> |
// +----------------------------------------------------------------------+
// $Id: mysql.php,v 1.10 2004/04/10 10:46:53 lsmith Exp $
require_once 'MDB2/Driver/Reverse/Common.php';
* MDB2 MySQL driver for the schema reverse engineering module
* @author Lukas Smith <smith@backendmedia.com>
// {{{ getTableFieldDefinition()
* get the stucture of a field into an array
* @param string $table name of table that should be used in method
* @param string $field_name name of field that should be used in method
* @return mixed data array on success, a MDB2 error on failure
$db = & $GLOBALS['_MDB2_databases'][$this->db_index];
if ($field_name == $db->dummy_primary_key ) {
'getTableFieldDefinition: '. $db->dummy_primary_key. ' is an hidden column');
$result = $db->query (" SHOW COLUMNS FROM $table" );
$columns = $result->getColumnNames ();
if (!isset ($columns[$column = 'field'])
|| !isset ($columns[$column = 'type']))
'getTableFieldDefinition: show columns does not return the column '. $column);
$field_column = $columns['field'];
$type_column = $columns['type'];
while (is_array($row = $result->fetchRow ())) {
if ($field_name == $row[$field_column]) {
$db_type = strtok($db_type, '(), ');
if ($db_type == 'national') {
if ($decimal == 'binary') {
} elseif ($length == '1') {
} elseif (strstr($db_type, 'text'))
foreach ($matches[0 ] as $value) {
'getTableFieldDefinition: unknown database attribute type');
if (isset ($columns['null'])
&& $row[$columns['null']] != 'YES')
if (isset ($columns['default'])
&& isset ($row[$columns['default']]))
$default = $row[$columns['default']];
for ($field_choices = array (), $datatype = 0; $datatype < count($type); $datatype++ ) {
$field_choices[$datatype] = array ('type' => $type[$datatype]);
$field_choices[$datatype]['notnull'] = true;
$field_choices[$datatype]['default'] = $default;
if ($type[$datatype] != 'boolean'
&& $type[$datatype] != 'time'
&& $type[$datatype] != 'date'
&& $type[$datatype] != 'timestamp')
$field_choices[$datatype]['length'] = $length;
$definition[0 ] = $field_choices;
if (isset ($columns['extra'])
&& isset ($row[$columns['extra']])
&& $row[$columns['extra']] == 'auto_increment')
$implicit_sequence = array ();
$implicit_sequence['on'] = array ();
$implicit_sequence['on']['table'] = $table;
$implicit_sequence['on']['field'] = $field_name;
$definition[1 ]['name'] = $table. '_'. $field_name;
$definition[1 ]['definition'] = $implicit_sequence;
if (isset ($columns['key'])
&& isset ($row[$columns['key']])
&& $row[$columns['key']] == 'PRI')
// check that its not just a unique field
$query = " SHOW INDEX FROM $table";
foreach ($indexes as $index) {
if ($index['key_name'] == 'PRIMARY' && $index['column_name'] == $field_name) {
$implicit_index = array ();
$implicit_index['unique'] = true;
$implicit_index['fields'][$field_name] = '';
$definition[2 ]['name'] = $field_name;
$definition[2 ]['definition'] = $implicit_index;
'getTableFieldDefinition: it was not specified an existing table column');
// {{{ getTableIndexDefinition()
* get the stucture of an index into an array
* @param string $table name of table that should be used in method
* @param string $index_name name of index that should be used in method
* @return mixed data array on success, a MDB2 error on failure
$db = & $GLOBALS['_MDB2_databases'][$this->db_index];
if ($index_name == 'PRIMARY') {
'getTableIndexDefinition: PRIMARY is an hidden index');
if (MDB2::isError($result = $db->query (" SHOW INDEX FROM $table" ))) {
if (!strcmp($index_name, $key_name)) {
if (!$row['non_unique']) {
$definition[$index_name]['unique'] = true;
$column_name = $row['column_name'];
$definition['fields'][$column_name] = array ();
if (isset ($row['collation'])) {
$definition['fields'][$column_name]['sorting'] = ($row['collation'] == 'A' ? 'ascending' : 'descending');
if (!isset ($definition['fields'])) {
'getTableIndexDefinition: it was not specified an existing table index');
* Returns information about a table or a result set.
* @param object|string $result MDB2_result object from a query or a
* string containing the name of a table
* @param int $mode a valid tableInfo mode
* @return array an associative array with the information requested
* or an error object if something is wrong
* @see MDB2_Driver_Common::tableInfo()
$db = & $GLOBALS['_MDB2_databases'][$this->db_index];
$case_func = 'strtolower';
* Probably received a table name.
* Create a result resource identifier.
$result, $db->connection );
* Probably received a result object.
* Extract the result resource identifier.
$id = $result->getResource ();
return $db->raiseError ();
// made this IF due to performance (one if is faster than $count if's)
for ($i=0 ,$j=0; $i< $count; $i++ ) {
if ($name != 'dummy_primary_key') {
$res[$j]['name'] = $name;
$res['num_fields']= $count;
for ($i=0 ,$j=0; $i< $count; $i++ ) {
if ($name != 'dummy_primary_key') {
$res[$j]['name'] = $name;
$res['order'][$res[$j]['name']] = $j;
$res['ordertable'][$res[$j]['table']][$res[$j]['name']] = $j;
// free the result only if we were called on a table
Documentation generated on Mon, 11 Mar 2019 10:15:51 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|