/** * Constructor * * Instantiate the DB writer object * * The DB table requires the following fields at a minimum: * timestamp DATETIME * level INT * name VARCHAR * message TEXT, VARCHAR, etc. * * @param \Pop\Db\Sql $sql * @param string $table * @throws Exception * @return Db */ public function __construct(\Pop\Db\Sql $sql, $table = null) { if (null !== $table) { $sql->setTable($table); } if (null === $sql->getTable()) { throw new Exception('Error: The SQL object does not have a table defined.'); } $this->sql = $sql; if (!in_array($sql->getTable(), $sql->db()->getTables())) { $this->createTable(); } }
public function testSetAndGetTable() { $s = new Sql(Db::factory('Sqlite', array('database' => __DIR__ . '/../tmp/test.sqlite')), 'users'); $s->setTable('user_data'); $this->assertEquals('user_data', $s->getTable()); }