示例#1
0
 protected function setUp()
 {
     $this->pdo = new Pdo('sqlite::memory:', null, null, array(Pdo::ATTR_ERRMODE => Pdo::ERRMODE_EXCEPTION));
     $this->pdo->exec('CREATE TABLE test(id INTEGER PRIMARY KEY, a TEXT)');
     $this->fake = $this->pdo->prepare('SELECT * FROM test WHERE a = :b');
     $this->real = $this->getPropertyValue($this->fake, 'statement');
 }
 /**
  * {@inheritDoc}
  */
 public function register(Application $app)
 {
     $app['pdo.factory'] = $app->protect(function ($dsn, $username = null, $password = null, array $options = array()) use($app) {
         if ($app['debug'] && isset($app['monolog'])) {
             $pdo = new PdoLog($dsn, $username, $password, $options);
             $pdo->onLog(function (array $entry) use($app) {
                 $app['monolog']->addDebug(sprintf('PDO query: %s, values :%s', $entry['query'], var_export($entry['values'], true)));
             });
             return $pdo;
         }
         return new PDO($dsn, $username, $password, $options);
     });
     $app['pdo'] = $app->share(function (Application $app) {
         foreach ($app['pdo.defaults'] as $name => $value) {
             if (!isset($app[$name])) {
                 $app[$name] = $value;
             }
         }
         return $app['pdo.factory']($app['pdo.dsn'], $app['pdo.username'], $app['pdo.password'], $app['pdo.options']);
     });
     $app['pdo.defaults'] = array('pdo.username' => null, 'pdo.password' => null, 'pdo.options' => array());
 }
示例#3
0
 public function testQueryError()
 {
     $this->pdo->setAttribute(Pdo::ATTR_ERRMODE, Pdo::ERR_NONE);
     $this->assertFalse($this->pdo->query('wat'));
 }