Exemplo n.º 1
0
 public function buildBatchQuery($data, $datafield)
 {
     $insert_values = array();
     foreach ($data as $d) {
         $question_marks[] = '(' . placeholders('?', sizeof($d)) . ')';
         $insert_values = array_merge($insert_values, array_values($d));
     }
     $sql = "INSERT INTO table (" . implode(",", array_keys($datafield)) . ") VALUES " . implode(',', $question_marks);
     return $sql;
 }
Exemplo n.º 2
0
 public function updateEntity($inTable, $updateData, $whereEntityKeyValue)
 {
     $entityColumnWhere = array_keys($whereEntityKeyValue)[0];
     $entityColumnWhereValue = $whereEntityKeyValue[$entityColumnWhere];
     function placeholders($text, $count = 0, $separator = ",")
     {
         $result = array();
         if ($count > 0) {
             for ($x = 0; $x < $count; $x++) {
                 $result[] = $text;
             }
         }
         return implode($separator, $result);
     }
     $this->_db->beginTransaction();
     $update_values = array();
     foreach ($updateData as $d) {
         $question_marks[] = placeholders('?', sizeof($d));
         array_push($update_values, $d);
     }
     $sql = "UPDATE {$inTable} SET (" . implode(",", array_keys($updateData)) . ")\n        VALUES (" . implode(',', $question_marks) . ") WHERE {$entityColumnWhere} = ?";
     $query = $this->_db->prepare($sql);
     $query->bindParam(1, $entityColumnWhereValue);
     try {
         $query->execute($update_values);
     } catch (\PDOException $e) {
         echo $e->getMessage();
     }
     $this->_db->commit();
 }