Exemple #1
0
 /**
  * @see phpDataMapper_Adapter_Interface::dropDatabase()
  */
 public function dropDatabase($database)
 {
     $sql = "DROP DATABASE " . $database;
     // Add query to log
     phpDataMapper::logQuery($sql);
     return $this->connection()->exec($sql);
 }
Exemple #2
0
 /**
  * Find records with custom SQL query
  *
  * @param string $sql SQL query to execute
  * @param array $binds Array of bound parameters to use as values for query
  * @throws phpDataMapper_Exception
  */
 public function query($sql, array $binds = array())
 {
     // Add query to log
     phpDataMapper::logQuery($sql, $binds);
     // Prepare and execute query
     if ($stmt = $this->adapter()->prepare($sql)) {
         $results = $stmt->execute($binds);
         if ($results) {
             $r = $this->getResultSet($stmt);
         } else {
             $r = false;
         }
         return $r;
     } else {
         throw new $this->_exceptionClass("Error: Unable to execute SQL query - failed to create" . " prepared statement from given SQL");
     }
 }
Exemple #3
0
 /**
  * Introspects the database to get current index information for the specified table.
  *
  * @param string $table The name of the table to inspect.
  * @return array An array, where the values are hashes of MySQL index info.
  */
 protected function indexInfoForTable($table)
 {
     $sql = "SHOW INDEX FROM `{$table}`";
     $stmt = $this->connection()->query($sql);
     phpDataMapper::logQuery($sql);
     return $stmt ? $stmt->fetchAll() : false;
 }
 public function testMathFunctions()
 {
     $mapper = $this->postMapper;
     try {
         $this->assertEquals($mapper->first(array('SQRT(id)' => 2))->id, 4);
         $this->assertEquals($mapper->first(array('COS(id-1)' => 1))->id, 1);
         $this->assertEquals($mapper->first(array('COS(id-1) + COS(id-1) =' => 2))->id, 1);
     } catch (Exception $e) {
         phpDataMapper::debug();
     }
 }