setTable() 공개 메소드

Set current table to operate on.
public setTable ( mixed $table = null ) : Sql
$table mixed
리턴 Sql
예제 #1
0
파일: Db.php 프로젝트: popphp/pop-log
 /**
  * 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();
     }
 }
예제 #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());
 }