setTable() public method

Set current table to operate on.
public setTable ( mixed $table = null ) : Sql
$table mixed
return Sql
Exemplo n.º 1
0
 /**
  * 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();
     }
 }
Exemplo n.º 2
0
 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());
 }