+ 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();
+
+
+
+ */
+ }
+