Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DB {
- public $mysqli;
- protected $db_name = 'ecards';
- protected $db_user = 'root';
- protected $db_pass = '1488';
- protected $db_host = 'localhost';
- public function connect() {
- $this->mysqli = new mysqli($this->db_host, $this->db_user, $this->db_pass, $this->db_name);
- if ($this->mysqli->connect_errno) {
- echo "Не удалось подключиться к MySQL: " . $this->mysqli->connect_error;
- } else {
- //echo 'Удалось подключиться к MySQL ';
- }
- }
- public function select($from, $where) {
- $res = $this->mysqli->query("SELECT * FROM $from WHERE $where");
- return $res->fetch_assoc();
- }
- /*
- $data = array(
- "username" => "'$this->username'",
- "password" => "'$this->hashedPassword'",
- "email" => "'$this->email'",
- "join_date" => "'".date("Y-m-d H:i:s",time())."'"
- );
- */
- public function update($data, $table, $where) {
- foreach ($data as $column => $value) {
- $sql = "UPDATE $table SET $column = $value WHERE $where";
- $this->mysqli->query($sql) or die($this->mysqli->error);
- }
- return true;
- }
- public function insert($data, $table) {
- $columns = "";
- $values = "";
- foreach ($data as $column => $value) {
- $columns .= ($columns == "") ? "" : ", ";
- $columns .= $column;
- $values .= ($values == "") ? "" : ", ";
- $values .= $value;
- }
- $sql = "INSERT INTO $table ($columns) VALUES ($values)";
- echo "$sql";
- $this->mysqli->query($sql) or die($this->mysqli->error);
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement