Subversion Repositories PHPX

Compare Revisions

Last modification

Ignore whitespace Rev 68 → Rev 69

/trunk/Db/Database.php
158,34 → 158,35
*/
public function readConfig ()
{
$config = parse_ini_file('application/.config', true);
if ($config !== false)
{
$section = 'database:' . $this->_dbname;
if (isset($config[$section]))
{
$dbconfig = $config[$section];
$options = array(
'host', 'port', 'dbname', 'username', 'password', 'charset'
);
/* FIXME: Configuration file path should not be hardcoded */
$config = parse_ini_file('application/.config', true);
if ($config !== false)
{
$section = 'database:' . $this->_dbname;
if (isset($config[$section]))
{
$dbconfig = $config[$section];
$options = array(
'host', 'port', 'dbname', 'username', 'password', 'charset'
);
 
foreach ($options as $key)
{
$property = "_$key";
if (isset($dbconfig[$key])
&& $key == 'dbname'
|| (property_exists($this, $property)
&& $this->$property === null))
{
$this->$property = $dbconfig[$key];
}
}
foreach ($options as $key)
{
$property = "_$key";
if (isset($dbconfig[$key])
&& ($key == 'dbname'
|| (property_exists($this, $property)
&& $this->$property === null)))
{
$this->$property = $dbconfig[$key];
}
}
 
return $config[$section];
}
}
return $config[$section];
}
}
 
return $config;
return $config;
}
 
/**
261,16 → 262,16
*/
protected function _columnDef (array $data, $column_name)
{
$def = (isset($data['unsigned']) && $data['unsigned'] ? 'UNSIGNED ' : '')
. $data['type']
. (isset($data['not_null']) && $data['not_null'] ? ' NOT NULL' : ' NULL')
. (isset($data['default']) && $data['default'] ? " DEFAULT {$data['default']}" : '')
. (isset($data['auto_inc']) && $data['auto_inc'] ? ' AUTO_INCREMENT' : '')
. (isset($data['unique']) && $data['unique'] ? ' UNIQUE KEY' : '')
. (isset($data['primary']) && $data['primary'] ? ' PRIMARY KEY' : '')
. (isset($data['comment']) && $data['comment'] ? " COMMENT '{$data['comment']}'" : '');
$def = (isset($data['unsigned']) && $data['unsigned'] ? 'UNSIGNED ' : '')
. $data['type']
. (isset($data['not_null']) && $data['not_null'] ? ' NOT NULL' : ' NULL')
. (isset($data['default']) && $data['default'] ? " DEFAULT {$data['default']}" : '')
. (isset($data['auto_inc']) && $data['auto_inc'] ? ' AUTO_INCREMENT' : '')
. (isset($data['unique']) && $data['unique'] ? ' UNIQUE KEY' : '')
. (isset($data['primary']) && $data['primary'] ? ' PRIMARY KEY' : '')
. (isset($data['comment']) && $data['comment'] ? " COMMENT '{$data['comment']}'" : '');
 
return $this->escapeName($column_name) . ' ' . $def;
return $this->escapeName($column_name) . ' ' . $def;
}
 
/**
285,15 → 286,15
*/
public function createTable ($name, array $columns, array $options = null)
{
$class = \get_class($this);
$query = 'CREATE TABLE '
. $this->escapeName($name)
. '('
. array_map(array($this, '_columnDef'), $columns, array_keys($columns)) . ')';
$class = \get_class($this);
$query = 'CREATE TABLE '
. $this->escapeName($name)
. '('
. array_map(array($this, '_columnDef'), $columns, array_keys($columns)) . ')';
 
$stmt = $this->prepare($query);
$stmt = $this->prepare($query);
 
/* DEBUG */
/* DEBUG */
if (defined('DEBUG') && DEBUG > 1)
{
debug(array(
639,8 → 640,8
if (defined('DEBUG') && DEBUG > 1)
{
debug(array(
'query' => $query,
'params' => $params
'query' => $query,
'params' => $params
));
}