Subversion Repositories PHPX

Rev

Rev 41 | Rev 47 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 41 Rev 44
Line 109... Line 109...
109
   * and testing purposes.
109
   * and testing purposes.
110
   *
110
   *
111
   * @param string $dsn
111
   * @param string $dsn
112
   * @param string $username
112
   * @param string $username
113
   * @param string $password
113
   * @param string $password
114
   * @param mixed $options
114
   * @param array $options
-
 
115
   * @see PDO::__construct()
115
   */
116
   */
116
  public function __construct($dsn = '', $username = null,
117
  public function __construct ($dsn = '', $username = null,
117
    $password = null, array $options = array())
118
    $password = null, array $options = array())
118
  {
119
  {
119
    if ($dsn !== '')
120
    if ($dsn !== '')
120
    {
121
    {
121
      $this->_dsn = $dsn;
122
      $this->_dsn = $dsn;
Line 150... Line 151...
150
151
151
    return $this->_connection;
152
    return $this->_connection;
152
  }
153
  }
153
154
154
  /**
155
  /**
-
 
156
   * Creates a database according to the specified parameters
-
 
157
   *
-
 
158
   * Should be overwritten and called by inheriting classes.
-
 
159
   *
-
 
160
   * @param string $dsn
-
 
161
   *   Connection DSN (required; must not include the database
-
 
162
   *   name).
-
 
163
   * @param string $username = null
-
 
164
   *   Connection username.  The default is specified by the
-
 
165
   *   <code>$_username</code> property.  Note that creating
-
 
166
   *   the database usually requires a user with more privileges
-
 
167
   *   than the one accessing the database or its tables.
-
 
168
   * @param string $password = null
-
 
169
   *   Connection password.  The default is specified by the
-
 
170
   *   <code>$_password</code> property.
-
 
171
   * @param array? $options = null
-
 
172
   *   Connection options.  The default is specified by the
-
 
173
   *   <code>$_options</code> property.
-
 
174
   * @param string $spec = null
-
 
175
   *   Additional database specifications, like character encoding
-
 
176
   *   and collation.
-
 
177
   * @param boolean $force = false
-
 
178
   *   If a true-value, the database will be attempted to be
-
 
179
   *   created even if there is a database of the name specified
-
 
180
   *   by the <code>$_dbname</code> property.
-
 
181
   * @return int
-
 
182
   *   The number of rows affected by the CREATE DATABASE statement.
-
 
183
   * @see PDO::__construct()
-
 
184
   * @see PDO::exec()
-
 
185
   */
-
 
186
  public function create ($dsn, $username = null, $password = null,
-
 
187
    array $options = null, $dbspec = null, $force = false)
-
 
188
  {
-
 
189
    $connection = new PDO($dsn,
-
 
190
      $username !== null ? $username : $this->_username,
-
 
191
      $password !== null ? $password : $this->_password,
-
 
192
      $options !== null ? $options : $this->_options);
-
 
193
-
 
194
    $query = 'CREATE DATABASE'
-
 
195
           . (!$force ? ' IF NOT EXISTS' : '')
-
 
196
           . ' ' . $this->escapeName($this->_dbname)
-
 
197
           . ($dbspec ? ' ' . $dbspec : '');
-
 
198
-
 
199
    return $connection->exec($query);
-
 
200
  }
-
 
201
-
 
202
  /**
155
   * Initiates a transaction
203
   * Initiates a transaction
156
   *
204
   *
157
   * @return bool
205
   * @return bool
158
   * @see PDO::beginTransaction()
206
   * @see PDO::beginTransaction()
159
   */
207
   */