private function dumpPeopleTable()
 {
     $allRows = CW_MySQL::getInstance()->query('SELECT * FROM people');
     $isFirstRow = true;
     $row = $allRows->fetch_assoc();
     do {
         if ($isFirstRow) {
             foreach ($row as $columnName => $columnValue) {
                 printf(self::ROW_FORMAT, $columnName);
                 echo ' ';
             }
             echo "\n";
         }
         foreach ($row as $columnName => $columnValue) {
             printf(self::ROW_FORMAT, $columnValue);
         }
         echo "\n";
     } while ($row = $allRows->fetch_assoc());
 }
Пример #2
0
 /**
  * Builds the order clauses from the incoming data, if any are present
  *
  * @param $order the order to build from
  * @return array containing the build SQL order clauses
  * @throws InvalidArgumentException in the event that any of the incoming data is invalid (i.e. ASK instead of ASC)
  */
 private function buildOrderClauses($order)
 {
     $orderClauses = array();
     if ($order != null) {
         array_walk($order, function ($val, $key) use(&$orderClauses) {
             $val = strtoupper(trim($val));
             if ($val != CW_MySQL::OP_ASC && $val != CW_MySQL::OP_DESC) {
                 throw new InvalidArgumentException('Order must either be ASC or DESC. Order column: ' . $key);
             }
             $orderClauses[] = CW_MySQL::escapeFieldName($key) . ' ' . $val;
         });
         return $orderClauses;
     }
     return $orderClauses;
 }
Пример #3
0
 public function testLastInsertId()
 {
     CW_MySQL::getInstance()->insert('people', array('firstname' => 'testLastInsertId', 'lastname' => 'User', 'age' => 50, 'createdDate' => time()));
     $lastInsertId = CW_MySQL::getInstance()->getLastInsertId();
     //$lastInsertOnly = CW_MySQL::getInstance()->select('people', array('firstname' => 'testLastInsertId'));
     $results = CW_MySQL::getInstance()->query('SELECT id, firstname FROM people WHERE id=' . $lastInsertId);
     $this->assertEquals(1, $results->num_rows, 'No row found by ID ' . $lastInsertId);
     $singleRow = $results->fetch_object();
     $this->assertEquals($singleRow->id, $lastInsertId, 'Insert ID from class does not match actual from database.');
     $this->assertEquals('testLastInsertId', $singleRow->firstname, 'Inserted name does not match row retrieved via inserted ID');
 }