3
* $Id: Mysql.php 4265 2008-04-19 18:28:29Z jwage $
5
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17
* This software consists of voluntary contributions made by many individuals
18
* and is licensed under the LGPL. For more information, see
19
* <http://www.phpdoctrine.org>.
23
* Doctrine_Connection_Mysql
26
* @subpackage Connection
27
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
28
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
29
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
30
* @version $Revision: 4265 $
31
* @link www.phpdoctrine.org
34
class Doctrine_Connection_Mysql extends Doctrine_Connection_Common
37
* @var string $driverName the name of this connection driver
39
protected $driverName = 'Mysql';
44
* @param Doctrine_Manager $manager
45
* @param PDO|Doctrine_Adapter $adapter database handler
47
public function __construct(Doctrine_Manager $manager, $adapter)
49
$this->setAttribute(Doctrine::ATTR_DEFAULT_TABLE_TYPE, 'INNODB');
50
$this->supported = array(
51
'sequences' => 'emulated',
53
'affected_rows' => true,
54
'transactions' => true,
55
'savepoints' => false,
56
'summary_functions' => true,
57
'order_by_text' => true,
58
'current_id' => 'emulated',
59
'limit_queries' => true,
62
'sub_selects' => true,
63
'auto_increment' => true,
64
'primary_key' => true,
65
'result_introspection' => true,
66
'prepared_statements' => 'emulated',
67
'identifier_quoting' => true,
68
'pattern_escaping' => true
71
$this->properties['string_quoting'] = array('start' => "'",
74
'escape_pattern' => '\\');
76
$this->properties['identifier_quoting'] = array('start' => '`',
80
$this->properties['sql_comments'] = array(
81
array('start' => '-- ', 'end' => "\n", 'escape' => false),
82
array('start' => '#', 'end' => "\n", 'escape' => false),
83
array('start' => '/*', 'end' => '*/', 'escape' => false),
86
$this->properties['varchar_max_length'] = 255;
88
parent::__construct($manager, $adapter);
92
* Overrides connect Method, to add specific attributes
93
* PDO emulate prepares is required to avoid bugs on mysql < 5.1
94
* when trying to prepare DROP DATABASE or CREATE DATABASE statements
96
* @see Doctrine_Connection :: connect();
97
* @return boolean connected
99
public function connect()
101
$connected = parent::connect();
102
$this->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
109
* returns the name of the connected database
113
public function getDatabaseName()
115
return $this->fetchOne('SELECT DATABASE()');
119
* Set the charset on the current connection
121
* @param string charset
123
public function setCharset($charset)
125
$query = 'SET NAMES ' . $this->quote($charset);
131
* Execute a SQL REPLACE query. A REPLACE query is identical to a INSERT
132
* query, except that if there is already a row in the table with the same
133
* key field values, the REPLACE query just updates its values instead of
134
* inserting a new row.
136
* The REPLACE type of query does not make part of the SQL standards. Since
137
* practically only MySQL implements it natively, this type of query is
138
* emulated through this method for other DBMS using standard types of
139
* queries inside a transaction to assure the atomicity of the operation.
143
* @param string $table name of the table on which the REPLACE query will
145
* @param array $fields associative array that describes the fields and the
146
* values that will be inserted or updated in the specified table. The
147
* indexes of the array are the names of all the fields of the table. The
148
* values of the array are also associative arrays that describe the
149
* values and other properties of the table fields.
151
* Here follows a list of field properties that need to be specified:
154
* Value to be assigned to the specified field. This value may be
155
* of specified in database independent type format as this
156
* function can perform the necessary datatype conversions.
159
* this property is required unless the Null property
163
* Name of the type of the field. Currently, all types Metabase
164
* are supported except for clob and blob.
166
* Default: no type conversion
169
* Boolean property that indicates that the value for this field
170
* should be set to null.
172
* The default value for fields missing in INSERT queries may be
173
* specified the definition of a table. Often, the default value
174
* is already null, but since the REPLACE may be emulated using
175
* an UPDATE query, make sure that all fields of the table are
176
* listed in this function argument array.
181
* Boolean property that indicates that this field should be
182
* handled as a primary key or at least as part of the compound
183
* unique index of the table that will determine the row that will
184
* updated if it exists or inserted a new row otherwise.
186
* This function will fail if no key field is specified or if the
187
* value of a key field is set to null because fields that are
188
* part of unique index they may not be null.
192
* @return integer the number of affected rows
194
public function replace(Doctrine_Table $table, array $fields, array $keys)
197
throw new Doctrine_Connection_Exception('Not specified which fields are keys');
203
foreach ($fields as $fieldName => $value) {
204
$columns[] = $table->getColumnName($fieldName);
209
$query = 'REPLACE INTO ' . $table->getTableName() . ' (' . implode(',', $columns) . ') VALUES (' . implode(',', $values) . ')';
211
return $this->exec($query, $params);
b'\\ No newline at end of file'