<?php
class ClsMySQL{
	private $cnn;
	public function __construct()
	{
		$username="cpglqvps_admgestion2026";
		$password="WINxp2026+++";
		$database="cpglqvps_gestion2026";
		$this->cnn= mysqli_connect("p:localhost",$username,$password,$database);
		//$this->cnn->set_charset("utf8mb4");
		$this->cnn->query("SET NAMES utf8mb4");
	}
	//
	function GetCnn(){
		return $this->cnn;
	}
	//
	function GET_ID(){
		return $this->cnn->insert_id;
	}
	//
	function Gss($sC,$sT,$sW){
		return (strlen($sW)>0) ? "Select $sC From $sT Where $sW" : "Select $sC From $sT";
	}
	//
	function GenId($StrId,$sT){
		$ss="Select Count(*) From $sT";
		$rs=$this->cnn->query($ss);
		$row = $rs->fetch_row();		
		if($row[0]==0){
			$StrIdEx=1;
		}else{
			$ss="Select Max($StrId) From $sT";
			$rs = $this->cnn->query($ss);
			$row = $rs->fetch_row();
			$StrIdEx=$row[0]+1;
		}
		return $StrIdEx;
	}
	//
	function GetC($sT,$sW){
		$ss=Gss("count(*)",$sT,$sW);
		$rs = $this->cnn->query($ss);
		$row = $rs->fetch_row();
		return (is_null($row[0])) ? 0 : $row[0];
	}
	//
	function gn($sC,$sT,$sW){
		$ss=Gss($sC,$sT,$sW);
		//echo $ss."<br>";
		$rs = $this->cnn->query($ss); 
		$row = $rs->fetch_row();
		return (is_null($row[0])) ? 0 : $row[0];
	}
	//
	function gs($sC,$sT,$sW){
		$ss=Gss($sC,$sT,$sW);
		$rs = $this->cnn->query($ss);
		$row = $rs->fetch_row();
		return (is_null($row[0])) ? "" : $row[0];
	}
	//
	public function grs($s){
		$rs = $this->cnn->query($s);	
		return $rs;
	}
	//
	function gr($t,$w){
		if(strlen($w)==0){
			$ss="SELECT * FROM ".$t;
		}else{
			$ss="SELECT * FROM ".$t." WHERE ".$w;
		}
		$rs = $this->cnn->query($ss);
		$row = $rs->fetch_assoc();	
		return $row;
	}
	//
	function ejt($ss){
		$rs = $this->cnn->query($ss);
		return $this->cnn->affected_rows;
	}
	//
	function ejt_ex($ss){
		return $this->cnn->query($ss);
	}
	//
	function ejt7($ss){
		if(mysqli_query($this->cnn,$ss)){
			return mysqli_insert_id($this->cnn);
		}else{
			return -1;
		}
	}
	//
	function EjtEx($ss){
		if(mysqli_query($this->cnn,$ss)){
			return mysqli_insert_id($this->cnn);
		}else{
			return 0;
		}
	}
}
?>