Пример #1
0
 /**
  * @inheritdoc
  */
 public function createCommand($sql = null, $params = [])
 {
     $this->open();
     $command = new Command(['db' => $this]);
     $command->setSql($sql, $params);
     return $command->bindValues($params);
 }
Пример #2
0
 /**
  * @covers \Intersvyaz\ExtDb\Command::bindValues
  */
 public function testBindValues()
 {
     $db = Yii::$app->db;
     $db->open();
     $lines = explode(';', file_get_contents(__DIR__ . '/data/fixture.sql'));
     foreach ($lines as $line) {
         if (trim($line) !== '') {
             $db->pdo->exec($line);
         }
     }
     $command = new Command(['db' => $db]);
     $params = ['desc' => '1', 'noparam' => ['bind' => false]];
     $command->setSql(__DIR__ . '/data/test.sql', $params);
     $command->bindValues($params);
     $this->assertRegExp('/^select\\s+\\*\\s+from\\s+profile\\s+where\\s+1=1\\s+and description = :desc$/', $command->getSql());
     $this->assertEquals([':desc' => '1'], $command->params);
 }