Untyp
authorJoey Schulze <joey@infodrom.org>
Fri, 4 Apr 2014 17:54:33 +0000 (17:54 +0000)
committerJoey Schulze <joey@infodrom.org>
Fri, 4 Apr 2014 17:54:33 +0000 (17:54 +0000)
class/ajaxbackend.class.php
class/database.class.php

index 505251c..304e20e 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
 <?php
 
-class AJAXBackend() {
+class AJAXBackend {
   private $db;
 
   public function __construct__()
   private $db;
 
   public function __construct__()
index 893f515..8b08da6 100644 (file)
@@ -155,6 +155,61 @@ class Database {
     return $result;
   }
 
     return $result;
   }
 
+  private function executeBind($sql, $data)
+  {
+    $sth = $this->db->prepare($sql);
+    if ($sth === false) return $this->handleError($sth,$sql);
+
+    foreach ($data as $k => $v)
+      $sth->bindValue(':'.$k, $v); // , PDO::PARAM_STR);
+
+    $ok = $this->db->execute();
+    if ($ok === false) return $this->handleError($sth,$sql);
+
+    if (preg_match('/INSERT\s+INTO\s+(\S+)\s+/i', $sql, $matches))
+      $this->lastInsertTable = $matches[1];
+
+    return $sth;
+  }
+
+  public function insertInto($table, $data)
+  {
+    if (!is_array($data)) throw Exception('insertInto called without data array');
+
+    $columns = array();
+    foreach ($data as $k => $v) {
+      $columns[] = $k;
+      $values[] = ':' . $k;
+    }
+
+    $sql = sprintf("INSERT INTO %s (%s)\n    VALUES (%s)",
+                  $table,
+                  implode(',', $columns),
+                  implode(',', $values));
+    return $this->executeBind($sql, $data);
+
+    /*
+   $db = new PDO('sqlsrv:server=SQLSERVERNAME;Database=own_exchange', 'user', 'password');
+   $sql = "INSERT INTO dbo.files(file_name, file_source) VALUES(:file_name, :file_source)";
+   $stmt = $db->prepare($sql);
+   $stmt->bindParam(":file_name", $files->name, PDO::PARAM_STR);
+   $stmt->bindParam(":file_source", file_get_contents($files->tempName), PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);
+   $stmt->execute();
+
+
+   $stmt = $dbh->prepare("INSERT INTO tExample (id,value) VALUES (:id,:value)");
+   $taValues = array(
+    'id' => '1',
+    'value' => '2'
+   ); // array
+   PDOBindArray($stmt,$taValues);
+   $stmt->execute();
+
+
+
+     */
+  }
+
 }
 
 ?>
 }
 
 ?>