Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: evtns
- * Date: 08/06/2016
- * Time: 17:55
- */
- class Database
- {
- private $db_ip = '127.0.0.1';
- private $db_user = 'root';
- private $db_pass = 'aaxd31mubr';
- private $db_select = 'sistema';
- public function connet(){
- $dbc = mysqli_connect($this->db_ip,$this->db_user,$this->db_pass) or die("falha ao conectar");
- if(mysqli_select_db($dbc, $this->db_select ))
- {
- echo 'DB selecionado com sucesso <br />';
- return $dbc;
- }
- else{
- echo 'falhou';
- return false;
- }
- }
- public function __construct()
- {
- }
- public function select($cols='*',$tables ,$where=null, $value=null, $order=null)
- {
- $query = "SELECT $cols ";
- $query .="FROM $tables ";
- if(isset($where) and isset($value))
- {
- $query .="WHERE $where='$value'";
- echo 'teste 1 ok';
- }
- if(isset($order))
- {
- $query .="ORDER BY $order";
- }
- if($result_query = mysqli_query($this->connet(), $query)){
- return $result_query;
- }
- echo 'Falha ao executar querry da função select.';
- return false;
- }
- public function insert($table,$val,$val1,$val2,$val3,$val4,$val5){
- switch ($table){
- case 'tbl_clientes':{
- $values = "INSERT INTO $table";
- $values .=" VALUES ('$val'";
- $values .=",'$val1'";
- $values .=",'$val2'";
- $values .=",'$val3'";
- $values .=",'$val4'";
- $values .=",$val5)";
- $function = mysqli_query($this->connet(), $values) or die("Falha ao adicionar cliente!");
- if($function){
- echo "Cliente $val1 adicionado com sucesso!";
- }
- else
- {
- echo "Falhou ao adicionar um cliente";
- }
- }
- }
- }
- public function update($table,$where,$where_v,$val1=null,$val2=null,$val3=null,$val4=null,$val5=null){
- switch($table){
- case 'tbl_clientes':
- $values ="UPDATE `$table` SET ";
- if(!empty($val1)){
- $values .="nome='$val1' ";
- if(!empty($val2)){
- $values .= ',';
- }
- }
- if(!empty($val2)){
- $values .="endereco='$val2' ";
- if(!empty($val3)){
- $values .= ',';
- }
- }
- if(!empty($val3)){
- $values .="telefone='$val3' ";
- if(!empty($val4)){
- $values .= ',';
- }
- }
- if(!empty($val4)){
- $values .="cidade='$val4' ";
- if(!empty($val5)){
- $values .= ',';
- }
- }
- if(!empty($val5)){
- $values .="num=$val5 ";
- }
- $values .="WHERE $where='$where_v'";
- echo $values;
- $result = mysqli_query($this->connet(), $values) or die("Falha ao atualizar cliente");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement