//$database - would be your PDO connection.
$query = $database->prepare("INSERT INTO users (name, password) VALUES name, :password)");
$query->bindParam(':name', "StackOverflow");
$query->bindParam(':password', "This is my ngu password.");
$query->execute();
$query->fetchAll();
class Database {
private $Connect, $Db;
public function __construct($host, $user, $pass, $data) {
if(!$this->Connect){
global $config;
try {
$this->b = new PDO("mysql:host={$host};dbname={$data}", $user, $pass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$this->Connect = true;
}catch(PDOException $e) {
die($e->getMessage());
}
}
}
public function lastInsertId() {
return $this->b->lastInsertId();
}
public function Query($q, $r = "", $d = null) {
try {
$data = $this->b->prepare($q);
$data->execute($d);
$dbErr = $data->errorInfo();
if ( $dbErr[0] != '00000' ) {
print_r($dbErr->errorInfo());
die();
}
switch(strtolower($r)) {
case "fetchall":
return $data->fetchAll();
case "fetch":
return $data->fetch(PDO::FETCH_ASSOC);
default:
return null;
}
} catch(PDOException $e) {
die($e->getMessage());
}
}
}
$database = new Database("127.0.0.1", "root", "examplepass", "exampledb");
$database->Query("INSERT INTO users (name, password) VALUES (?, ?)", "", array("StackOverflow", "This is my ngu password."));
//$database - would be your PDO connection.
$query = $database->prepare("INSERT INTO users (name, password) VALUES name, :password)");
$query->bindParam(':name', "StackOverflow");
$query->bindParam(':password', "This is my ngu password.");
$query->execute();
$query->fetchAll();
class Database {
private $Connect, $Db;
public function __construct($host, $user, $pass, $data) {
if(!$this->Connect){
global $config;
try {
$this->b = new PDO("mysql:host={$host};dbname={$data}", $user, $pass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$this->Connect = true;
}catch(PDOException $e) {
die($e->getMessage());
}
}
}
public function lastInsertId() {
return $this->b->lastInsertId();
}
public function Query($q, $r = "", $d = null) {
try {
$data = $this->b->prepare($q);
$data->execute($d);
$dbErr = $data->errorInfo();
if ( $dbErr[0] != '00000' ) {
print_r($dbErr->errorInfo());
die();
}
switch(strtolower($r)) {
case "fetchall":
return $data->fetchAll();
case "fetch":
return $data->fetch(PDO::FETCH_ASSOC);
default:
return null;
}
} catch(PDOException $e) {
die($e->getMessage());
}
}
}
$database = new Database("127.0.0.1", "root", "examplepass", "exampledb");
$database->Query("INSERT INTO users (name, password) VALUES (?, ?)", "", array("StackOverflow", "This is my ngu password."));
Copyright © 2024, NextGenUpdate.
All Rights Reserved.