Rev 52 | Rev 61 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 52 | Rev 58 | ||
|---|---|---|---|
| Line 228... | Line 228... | ||
| 228 | * @see PDO::exec()
|
228 | * @see PDO::exec()
|
| 229 | */
|
229 | */
|
| 230 | public function create ($dsn, $username = null, $password = null, |
230 | public function create ($dsn, $username = null, $password = null, |
| 231 | array $options = null, $dbspec = null, $force = false) |
231 | array $options = null, $dbspec = null, $force = false) |
| 232 | {
|
232 | {
|
| 233 | $connection = new PDO($dsn, |
233 | $connection = new \PDO($dsn, |
| 234 | $username !== null ? $username : $this->_username, |
234 | $username !== null ? $username : $this->_username, |
| 235 | $password !== null ? $password : $this->_password, |
235 | $password !== null ? $password : $this->_password, |
| 236 | $options !== null ? $options : $this->_options); |
236 | $options !== null ? $options : $this->_options); |
| 237 | 237 | ||
| 238 | $query = 'CREATE DATABASE' |
238 | $query = 'CREATE DATABASE' |
| Line 242... | Line 242... | ||
| 242 | 242 | ||
| 243 | return $connection->exec($query); |
243 | return $connection->exec($query); |
| 244 | }
|
244 | }
|
| 245 | 245 | ||
| 246 | /**
|
246 | /**
|
| - | 247 | * Maps column meta-information to a column definition.
|
|
| - | 248 | *
|
|
| - | 249 | * Should be overwritten and called by inheriting classes.
|
|
| - | 250 | *
|
|
| - | 251 | * @todo
|
|
| - | 252 | * @param array $value
|
|
| - | 253 | * @param string $column_name
|
|
| - | 254 | * @return string
|
|
| - | 255 | */
|
|
| - | 256 | protected function _columnDef (array $data, $column_name) |
|
| - | 257 | {
|
|
| - | 258 | $def = (isset($data['unsigned']) && $data['unsigned'] ? 'UNSIGNED ' : '') |
|
| - | 259 | . $data['type'] |
|
| - | 260 | . (isset($data['not_null']) && $data['not_null'] ? ' NOT NULL' : ' NULL') |
|
| - | 261 | . (isset($data['default']) && $data['default'] ? " DEFAULT {$data['default']}" : '') |
|
| - | 262 | . (isset($data['auto_inc']) && $data['auto_inc'] ? ' AUTO_INCREMENT' : '') |
|
| - | 263 | . (isset($data['unique']) && $data['unique'] ? ' UNIQUE KEY' : '') |
|
| - | 264 | . (isset($data['primary']) && $data['primary'] ? ' PRIMARY KEY' : '') |
|
| - | 265 | . (isset($data['comment']) && $data['comment'] ? " COMMENT '{$data['comment']}'" : ''); |
|
| - | 266 | ||
| - | 267 | return $this->escapeName($column_name) . ' ' . $def; |
|
| - | 268 | }
|
|
| - | 269 | ||
| - | 270 | /**
|
|
| - | 271 | * Creates a database table according to the specified parameters
|
|
| - | 272 | *
|
|
| - | 273 | * @todo
|
|
| - | 274 | * @param string $name
|
|
| - | 275 | * @param array $columns
|
|
| - | 276 | * @param array $options = null
|
|
| - | 277 | * @return bool
|
|
| - | 278 | * @see PDOStatement::execute()
|
|
| - | 279 | */
|
|
| - | 280 | public function createTable ($name, array $columns, array $options = null) |
|
| - | 281 | {
|
|
| - | 282 | $class = \get_class($this); |
|
| - | 283 | $query = 'CREATE TABLE ' |
|
| - | 284 | . $this->escapeName($name) |
|
| - | 285 | . '(' |
|
| - | 286 | . array_map(array($this, '_columnDef'), $columns, array_keys($columns)) . ')'; |
|
| - | 287 | ||
| - | 288 | $stmt = $this->prepare($query); |
|
| - | 289 | ||
| - | 290 | /* DEBUG */
|
|
| - | 291 | if (defined('DEBUG') && DEBUG > 1) |
|
| - | 292 | {
|
|
| - | 293 | debug(array( |
|
| - | 294 | 'query' => $query, |
|
| - | 295 | )); |
|
| - | 296 | }
|
|
| - | 297 | ||
| - | 298 | $success =& $this->_lastSuccess; |
|
| - | 299 | $success = $stmt->execute(); |
|
| - | 300 | ||
| - | 301 | $errorInfo =& $this->_lastError; |
|
| - | 302 | $errorInfo = $stmt->errorInfo(); |
|
| - | 303 | ||
| - | 304 | $this->_resetLastInsertId(); |
|
| - | 305 | ||
| - | 306 | $result =& $this->_lastResult; |
|
| - | 307 | $result = $stmt->fetchAll(); |
|
| - | 308 | ||
| - | 309 | if (defined('DEBUG') && DEBUG > 1) |
|
| - | 310 | {
|
|
| - | 311 | debug(array( |
|
| - | 312 | '_lastSuccess' => $success, |
|
| - | 313 | '_lastError' => $errorInfo, |
|
| - | 314 | '_lastResult' => $result |
|
| - | 315 | )); |
|
| - | 316 | }
|
|
| - | 317 | ||
| - | 318 | return $success; |
|
| - | 319 | }
|
|
| - | 320 | ||
| - | 321 | /**
|
|
| 247 | * Initiates a transaction
|
322 | * Initiates a transaction
|
| 248 | *
|
323 | *
|
| 249 | * @return bool
|
324 | * @return bool
|
| 250 | * @see PDO::beginTransaction()
|
325 | * @see PDO::beginTransaction()
|
| 251 | */
|
326 | */
|