Source for file Mysql.php
Documentation is available at Mysql.php
* $Id: Mysql.php 2081 2007-07-26 19:52:12Z zYne $
* 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 COPYRIGHT
* OWNER 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.
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @version $Revision: 2081 $
* @category Object Relational Mapping
* @link www.phpdoctrine.com
'showDatabases' =>
'SHOW DATABASES',
'listTableFields' =>
'DESCRIBE %s',
'listSequences' =>
'SHOW TABLES',
'listTables' =>
'SHOW TABLES',
'listUsers' =>
'SELECT DISTINCT USER FROM USER',
'listViews' =>
"SHOW FULL TABLES %sWHERE Table_type = 'VIEW'",
* lists all database sequences
* @param string|null$database
$query .=
' FROM ' .
$database;
$tableNames =
$this->conn->fetchColumn($query);
return array_map(array($this->conn, 'fixSequenceName'), $tableNames);
* lists table constraints
* @param string $table database table name
$nonUnique =
'Non_unique';
if ($this->conn->options['field_case'] ==
CASE_LOWER) {
$table =
$this->conn->quoteIdentifier($table, true);
$query =
'SHOW INDEX FROM ' .
$table;
$indexes =
$this->conn->fetchAssoc($query);
foreach ($indexes as $indexData) {
if (!$indexData[$nonUnique]) {
if ($indexData[$keyName] !==
'PRIMARY') {
$index =
$this->conn->fixIndexName($indexData[$keyName]);
* lists table foreign keys
* @param string $table database table name
$sql =
'SHOW CREATE TABLE ' .
$this->conn->quoteIdentifier($table, true);
* lists table constraints
* @param string $table database table name
$sql =
'DESCRIBE ' .
$this->conn->quoteIdentifier($table, true);
$result =
$this->conn->fetchAssoc($sql);
foreach ($result as $key =>
$val) {
$decl =
$this->conn->dataDict->getPortableDeclaration($val);
$values = isset
($decl['values']) ?
$decl['values'] :
array();
'type' =>
$decl['type'][0],
'alltypes' =>
$decl['type'],
'length' =>
$decl['length'],
'fixed' =>
$decl['fixed'],
'unsigned' =>
$decl['unsigned'],
'default' =>
$val['default'],
'notnull' => (bool)
($val['null'] !=
'YES'),
'autoinc' => (bool)
(strpos($val['extra'], 'auto_increment') !==
false),
$columns[$val['field']] =
$description;
* lists table constraints
* @param string $table database table name
$nonUnique =
'Non_unique';
if ($this->conn->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) {
if ($this->conn->options['field_case'] ==
CASE_LOWER) {
$table =
$this->conn->quoteIdentifier($table, true);
$query =
'SHOW INDEX FROM ' .
$table;
$indexes =
$this->conn->fetchAssoc($query);
foreach ($indexes as $indexData) {
if ($indexData[$nonUnique] &&
($index =
$this->conn->fixIndexName($indexData[$keyName]))) {
* @param string|null$database
return $this->conn->fetchColumn($this->sql['listTables']);
* @param string|null$database
$query =
sprintf($this->sql['listViews'], ' FROM ' .
$database);
return $this->conn->fetchColumn($query);