Ejemplo n.º 1
0
 /**
  * 执行SQL语句
  * @access public
  * @param string $sql  SQL指令
  * @param mixed $parse  是否需要解析SQL
  * @return false | integer
  */
 public function execute($sql, $parse = false)
 {
     if (!is_bool($parse) && !is_array($parse)) {
         $parse = func_get_args();
         array_shift($parse);
     }
     $sql = $this->parseSql($sql, $parse);
     return $this->db->execute($sql);
 }
Ejemplo n.º 2
0
 public function execute($values = array())
 {
     global $debug;
     $debug->printArray($values, '$values');
     try {
         $t = parent::execute($values);
         // maybe do some logging here?
     } catch (PDOException $e) {
         // maybe do some logging here?
         die('funkytown2');
         //throw $e . $debug;
     }
     return $t;
 }
Ejemplo n.º 3
0
<?php

$dir = 'sqlite:./record.sqlite';
$dbh = new PDO($dir) or die("cannot open the database");
$sql = "CREATE TABLE record(id INTEGER, type, name, value, ctime, mtime PRIMARY KEY(id DESC));";
$dbh->execute($sql);
$dhb->execute("insert record values(1, 1, 'chen', 26, '2016-5-23 21:39:17', '2016-5-23 21:39:28')");
Ejemplo n.º 4
0
<?php

$oDb = new PDO("sqlite:" . __DIR__ . "/cds.sqlite");
//$sQuery =  "';DROP DATABASE testme;#'";
$sQuery = "pop";
if (isset($_GET['Genre'])) {
    $sQuery = $_GET['Genre'];
}
$oDb->prepare("SELECT * FROM `cds` WHERE genre = :genre");
$oDb->bindParam("genre", $sQuery);
$oDb->execute();
$aResults = $oDb->fetchAll(PDO::FETCH_OBJ);
echo json_encode($aResults);
            } else {
                $filename = time() . '_' . $_FILES['profilePicture']['name'];
                while (file_exists(SERVER_PATH . 'img\\' . $filename)) {
                    $filename = time() . '_' . $_FILES['profilePicture']['name'];
                }
                move_uploaded_file($_FILES['profilePicture']['tmp_name'], SERVER_PATH . 'img\\' . $filename);
            }
        }
    } else {
        new Message("Ongeldig bestand");
        header("location: gegevens-wijzigen-form.php");
    }
    if ($filename) {
        $queriegeg = 'UPDATE users SET profile_picture = :profile_picture WHERE id = :id';
        $placeholders = array(':profile_picture' => $filename, ':id' => $user->getId());
        $databaseWrapper->query($queriegeg, $placeholders);
        new Message("De gegevens zijn gewijzigd!", "success");
        header("location: gegevens-wijzigen-form.php");
    }
    if (isset($_POST['email'])) {
        $email = $_POST['email'];
        $querie = 'UPDATE users SET email = :email WHERE id = :id';
        $db->prepare($querie);
        $db->binvalue(':id', $user->getId());
        $db->binvalue(':email', $email);
        $db->execute();
    } else {
        $error = new Message("Vul een e-mailadres of een paswoord in", "error");
        relocate('registratie-form.php');
    }
}
Ejemplo n.º 6
0
 public function save()
 {
     # Table Name && Created/Updated Fields
     $table_name = $this->table_name();
     $data = $this->record;
     $time = date('Y-m-d H:i:s');
     if (is_array($this->record)) {
         //existing
         $data = $this->record[0];
         $data->updated_at = $time;
         if (isset($data->id)) {
             $this->id = $data->id;
         } else {
             // return false;
         }
     } else {
         //new record
         $data = $this->record;
         $data->created_at = $time;
         $data->updated_at = '0000-00-00 00:00:00';
     }
     $properties = $this->loadPropertiesFromDatabase();
     # Create SQL Query
     $sql_set_string = '';
     $total_properties_count = count($properties);
     $x = 0;
     // first create values
     foreach ($properties as $k => $v) {
         $val = $v->Field;
         $type = $v->Type;
         if ($data->{$val} == NULL) {
             $values[] = '';
         } else {
             $values[] = str_replace("`", "``", $data->{$val});
         }
         $x++;
     }
     // set the sql statement
     if (count($values) != $total_properties_count) {
         $total_properties_count = count($values);
     }
     $x = 0;
     foreach ($properties as $k => $v) {
         $val = $v->Field;
         $type = $v->Type;
         $sql_set_string .= '`' . $val . '` = ?';
         if ($x < $total_properties_count - 1) {
             $sql_set_string .= ', ';
         } else {
             $sql_set_string .= '';
         }
         $x++;
     }
     # Final SQL Statement
     $sql2 = '`' . $table_name . "` SET " . $sql_set_string;
     if ($this->exists()) {
         $final_sql = 'UPDATE ' . $sql2 . ' WHERE `id` = ?;';
         $values[] = $data->id;
     } else {
         $final_sql = "INSERT INTO " . $sql2 . ';';
     }
     if (static::validate() === false) {
         return false;
     }
     $q = false;
     if ($this->validate()) {
         $q = $this->db->execute($final_sql, $values);
         $this->lastId = $this->db->lastId;
     }
     if ($q) {
         return true;
     } else {
         return false;
     }
 }