<?php
include_once("Database_dev.php");
 
class Crud_dev extends Database_dev{

    public function __construct(){
        parent::__construct();
    }

    public function conn(){
        return $this->connection;
    }

    public function count($query){
        $result = $this->connection->query($query);
        return $result ? $result->num_rows : 0;
    }
    
    public function getData($query){
        $result = $this->connection->query($query);
        if($result == false){
            return false;
        }
        $rows = array();
        while($row = $result->fetch_assoc()){
            $rows[] = $row;
        }
        return $rows;
    }

    public function getById($query){
        $result = $this->connection->query($query);
        if($result == false){
            return false;
        }
        $rows = array();
        $rows = $result->fetch_assoc();
        return $rows;
    }
        
    public function execute($query){
        $result = $this->connection->query($query);
        if($result == false){
            return false;
        }else{
            return true;
        }        
    }
    public function execute_id($query){
        $mysqli = $this->connection->query($query);
        $result = $this->connection->insert_id;
        if($result > 0){
            return $result;
        }else{
            return "0";
        }        
    }
    public function execute_query($query){
        $result = $this->connection->query($query);
        if($result == false){
            return "0";
        }else{
            return "1";
        }        
    }
    public function escape_string($value){
        return $this->connection->real_escape_string($value);
    }
    
}
?>