Subversion Repositories PHPX

Compare Revisions

Last modification

Ignore whitespace Rev 43 → Rev 44

/trunk/Db/MySQLDB.php
59,4 → 59,20
 
parent::__construct();
}
 
/**
* Creates this MySQL database
*
* @param string $username = null
* @param string $password = null
* @param boolean $force = false
* @see Database::create()
*/
public function create ($username = null, $password = null, $force = false)
{
return parent::create(
"mysql:host={$this->_host}"
. (!is_null($this->_charset) ? ";charset={$this->_charset}" : ''),
$username, $password, null, $force);
}
}
/trunk/Db/Database.php
111,9 → 111,10
* @param string $dsn
* @param string $username
* @param string $password
* @param mixed $options
* @param array $options
* @see PDO::__construct()
*/
public function __construct($dsn = '', $username = null,
public function __construct ($dsn = '', $username = null,
$password = null, array $options = array())
{
if ($dsn !== '')
152,6 → 153,53
}
 
/**
* Creates a database according to the specified parameters
*
* Should be overwritten and called by inheriting classes.
*
* @param string $dsn
* Connection DSN (required; must not include the database
* name).
* @param string $username = null
* Connection username. The default is specified by the
* <code>$_username</code> property. Note that creating
* the database usually requires a user with more privileges
* than the one accessing the database or its tables.
* @param string $password = null
* Connection password. The default is specified by the
* <code>$_password</code> property.
* @param array? $options = null
* Connection options. The default is specified by the
* <code>$_options</code> property.
* @param string $spec = null
* Additional database specifications, like character encoding
* and collation.
* @param boolean $force = false
* If a true-value, the database will be attempted to be
* created even if there is a database of the name specified
* by the <code>$_dbname</code> property.
* @return int
* The number of rows affected by the CREATE DATABASE statement.
* @see PDO::__construct()
* @see PDO::exec()
*/
public function create ($dsn, $username = null, $password = null,
array $options = null, $dbspec = null, $force = false)
{
$connection = new PDO($dsn,
$username !== null ? $username : $this->_username,
$password !== null ? $password : $this->_password,
$options !== null ? $options : $this->_options);
 
$query = 'CREATE DATABASE'
. (!$force ? ' IF NOT EXISTS' : '')
. ' ' . $this->escapeName($this->_dbname)
. ($dbspec ? ' ' . $dbspec : '');
 
return $connection->exec($query);
}
 
/**
* Initiates a transaction
*
* @return bool