Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include_once 'connection.php';
- class DbModels
- {
- protected $dbTableName;
- protected $sort;
- protected $dbTableParam;
- function __construct(){
- //$x = include '../configs/config.php';
- $this->conn = new DataBase('mysql.hostinger.pl','u322614235_admin','zaq1@WSX','u322614235_prime');
- }
- public function add($data){
- $i ='';
- $v ='';
- foreach ($data as $item=>$value ) {
- $i .= $item.",";
- $v .= "'".$value."',";
- }
- $i = substr($i, 0, -1);
- $v = substr($v, 0, -1);
- $sql = "INSERT INTO $this->dbTableName ($i) VALUES ($v)";
- if ($this->conn->query($sql)){
- return true;
- }
- echo $sql;
- }
- public function edit($data){
- $x ='';
- if(!key_exists('id',$data)){
- throw new Exception('Brak identyfikatora');
- }
- foreach ($data as $item=>$value ) {
- $x .= $item."='".$value."',";
- }
- $x = substr($x, 0, -1);
- $sql="UPDATE $this->dbTableName SET $x WHERE id=$data[id]";
- if ($this->conn->query($sql)){
- return true;
- }
- }
- public function delete($id){
- $sql="DELETE FROM $this->dbTableName WHERE id=$id";
- if ($this->conn->query($sql)){
- return true;
- }
- }
- public function getList(){
- $sql = "SELECT * FROM $this->dbTableName ORDER BY $this->sort";
- $return = $this->conn->queryAndRows($sql);
- return $return;
- }
- public function getOne($item,$value){
- $sql = "SELECT * FROM $this->dbTableName WHERE $item = LCASE('$value')";
- $return = $this->conn->queryAndRow($sql);
- return $return;
- }
- public function getOneA($item,$value,$item2,$value2){
- $sql = "SELECT * FROM $this->dbTableName WHERE $item = LCASE('$value') AND $item2 = LCASE('$value2')";
- $return = $this->conn->queryAndRow($sql);
- return $return;
- }
- public function getConnList($id){
- $sql = "
- select
- *
- from
- user$this->dbTableName as f
- join $this->dbTableName as s on f.$this->dbTableParam = s.id
- left join users as u on u.id = f.userID
- where
- u.id = $id
- ";
- $return = $this->conn->queryAndRows($sql);
- return $return;
- }
- public function deleteConn($idU,$idM){
- $sql="DELETE FROM user$this->dbTableName WHERE userID=$idU AND $this->dbTableParam=$idM";
- if ($this->conn->query($sql)){
- return true;
- }
- }
- public function addConn($idU,$idM){
- $sql = "INSERT INTO user$this->dbTableName (userID,$this->dbTableParam) VALUES ($idU,$idM)" ;
- if ($this->conn->query($sql)){
- return true;
- }
- echo $sql;
- }
- public function getOneConn($item,$value,$item2,$value2){
- $sql = "SELECT * FROM user$this->dbTableName WHERE $item = LCASE('$value') AND $item2 = LCASE('$value2')";
- $return = $this->conn->queryAndRow($sql);
- return $return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement