Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Create the database during setup if it does not already exist

  • Loading branch information...
commit b01de568ea8757d3304a379d652a59ec3e6117e6 1 parent c36c1fb
@haraldpdl haraldpdl authored
View
14 osCommerce/OM/Core/PDO/MySQL/Standard.php
@@ -33,18 +33,24 @@ public function __construct($server, $username, $password, $database, $port, $dr
}
public function connect() {
- $dsn = 'mysql:dbname=' . $this->_database;
+ $dsn_array = array();
+
+ if ( !empty($this->_database) ) {
+ $dsn_array[] = 'dbname=' . $this->_database;
+ }
if ( (strpos($this->_server, '/') !== false) || (strpos($this->_server, '\\') !== false) ) {
- $dsn .= ';unix_socket=' . $this->_server;
+ $dsn_array[] = 'unix_socket=' . $this->_server;
} else {
- $dsn .= ';host=' . $this->_server;
+ $dsn_array[] = 'host=' . $this->_server;
if ( !empty($this->_port) ) {
- $dsn .= ';port=' . $this->_port;
+ $dsn_array[] = 'port=' . $this->_port;
}
}
+ $dsn = 'mysql:' . implode(';', $dsn_array);
+
$this->_connected = true;
$dbh = parent::__construct($dsn, $this->_username, $this->_password, $this->_driver_options);
View
8 osCommerce/OM/Core/Site/Setup/Application/Install/Model/checkDB.php
@@ -8,10 +8,18 @@
namespace osCommerce\OM\Core\Site\Setup\Application\Install\Model;
+ use osCommerce\OM\Core\OSCOM;
use osCommerce\OM\Core\PDO;
+ use osCommerce\OM\Core\Registry;
class checkDB {
public static function execute($data) {
+ if ( $OSCOM_PDO = PDO::initialize($data['server'], $data['username'], $data['password'], null, $data['port'], $data['class']) ) {
+ Registry::set('PDO', $OSCOM_PDO);
+
+ OSCOM::callDB('Setup\Install\CreateDB', array('database' => $data['database']));
+ }
+
return PDO::initialize($data['server'], $data['username'], $data['password'], $data['database'], $data['port'], $data['class']);
}
}
View
20 osCommerce/OM/Core/Site/Setup/Application/Install/SQL/MySQL/Standard/CreateDB.php
@@ -0,0 +1,20 @@
+<?php
+/**
+ * osCommerce Online Merchant
+ *
+ * @copyright Copyright (c) 2011 osCommerce; http://www.oscommerce.com
+ * @license BSD License; http://www.oscommerce.com/bsdlicense.txt
+ */
+
+ namespace osCommerce\OM\Core\Site\Setup\Application\Install\SQL\MySQL\Standard;
+
+ use osCommerce\OM\Core\Registry;
+
+ class CreateDB {
+ public static function execute($data) {
+ $OSCOM_PDO = Registry::get('PDO');
+
+ return ($OSCOM_PDO->exec('create database if not exists `' . $data['database'] . '` CHARACTER SET utf8 COLLATE utf8_general_ci') !== false);
+ }
+ }
+?>
Please sign in to comment.
Something went wrong with that request. Please try again.