* General - Added Base.php for general getters and setters * Application.php - Reverted bad pretty printing * database.class.php (legacy file) - Fixed Googlebot-blocking bogus constant reference * Database.php, Table.php - Support constructor parameters to override properties
/trunk/Db/Database.php |
---|
95,44 → 95,8 |
*/ |
protected $_lastInsertId = ''; |
/** |
* Creates a new <code>Database</code> instance. |
* |
* Each of the parameters is optional and can also be given |
* by a protected property where the parameter name is preceded |
* by <code>_</code>. Parameter values overwrite the default |
* property values. It is recommended to use default property |
* values of inheriting classes except for small applications |
* and testing purposes. |
* |
* @param string $dsn |
* @param string $username |
* @param string $password |
* @param mixed $options |
*/ |
public function __construct($dsn = '', $username = null, |
$password = null, array $options = array()) |
public function __construct() |
{ |
if ($dsn !== '') |
{ |
$this->_dsn = $dsn; |
} |
if ($username !== null) |
{ |
$this->_username = $username; |
} |
if ($password !== null) |
{ |
$this->_password = $password; |
} |
if ($options) |
{ |
$this->_options = $options; |
} |
$this->_connection = |
new PDO($this->_dsn, $this->_username, $this->_password, $this->_options); |
} |
424,10 → 388,8 |
if (is_array($where) && $this->_isAssociativeArray($where)) |
{ |
/* FIXME: Export and reuse this */ |
foreach ($where as $column => $condition) |
{ |
/* TODO: Also handle function calls as keys */ |
if (is_array($condition) && $this->_isAssociativeArray($condition)) |
{ |
reset($condition); |
/trunk/Db/Table.php |
---|
1,6 → 1,5 |
<?php |
require_once __DIR__ . '/../Application.php'; |
require_once __DIR__ . '/../AbstractModel.php'; |
/** |
11,7 → 10,7 |
* ID of the last inserted row, or the last value from |
a sequence object, depending on the underlying driver. |
*/ |
class Table extends AbstractModel |
abstract class Table extends AbstractModel |
{ |
/** |
* Name of the table |
26,52 → 25,11 |
protected $_id = 'id'; |
/** |
* Creates a new <code>Table</code> instance. |
* |
* Each of the parameters is optional and can also be given |
* by a protected property where the parameter name is preceded |
* by <code>_</code>. Parameter values overwrite the default |
* property values. It is recommended to use default property |
* values of inheriting classes except for small applications |
* and testing purposes. |
* |
* @param Database $database |
* Database of the table (required in order to use a fitting |
* query language) |
* @param string $name |
* Table name |
* @param string $id |
* Name of the primary key column |
* @throws InvalidArgumentException |
*/ |
public function __construct(Database $database = null, $name = '', $id = '') |
public function __construct() |
{ |
if ($database === null) |
{ |
$this->_database = Application::getInstance()->getDefaultDatabase(); |
} |
else |
{ |
$this->_database = $database; |
} |
if ($name !== '') |
{ |
$this->_name = $name; |
} |
if (!$this->_name) |
{ |
throw new InvalidArgumentException('a table name is required'); |
} |
if ($id !== '') |
{ |
$this->_id = $id; |
} |
} |
/** |
* Returns the database for the table |
* @return Database |
/trunk/Db/database.class.php |
---|
1,6 → 1,6 |
<?php |
require_once __DIR__ . '/../global.inc'; |
require_once __LIB__ . '/../global.inc'; |
/* NOTE: Obsolete with autoloader */ |
//require_once 'Zend/Registry.php'; |