Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if(defined("include_banco_class") === false){
- define("include_banco_class", true);
- define("HOST", 0);
- define("USER", 1);
- define("PASS", 2);
- define("DB", 3);
- class banco{
- private $con = null;
- private $host = null;
- private $user = null;
- private $pass = null;
- private $db = null;
- public function __construct($host = null, $user = null, $pass = null, $db = null){
- if($host === null or $user === null or $pass === null or $db === null){
- $this->host = "localhost";
- $this->user = "root";
- $this->pass = "";
- $this->db = "lnd";
- }
- else{
- $this->host = $host;
- $this->user = $user;
- $this->pass = $pass;
- $this->db = $db;
- }
- return true;
- }
- public function SetVar($val, $type){
- switch(intval($type)){
- case HOST:{
- $this->host = $val;
- return true;
- }
- case USER:{
- $this->user = $val;
- return true;
- }
- case PASS:{
- $this->pass = $val;
- return true;
- }
- case DB:{
- $this->db = $val;
- return true;
- }
- default:{
- return false;
- }
- }
- return false;
- }
- public function connect(){
- if($this->host === null or $this->user === null or $this->pass === null or $this->db === null){
- return false;
- }
- if($this->con !== null){
- return false;
- }
- $this->con = new mysqli($this->host, $this->user, $this->pass, $this->db);
- if($this->con->connect_error){
- echo utf8_encode("Erro ao se conectar ao banco de dados:<br/>".$this->con->connect_errno."<br/>".$this->con->connect_error);
- $this->con = null;
- return false;
- }
- return true;
- }
- public function connected(){
- if($this->con === null || $this->con === false){
- return false;
- }
- return true;
- }
- public function query($query){
- if($this->con === null || $this->con === false){
- return false;
- }
- return $this->con->query($query);
- }
- public function insert_id(){
- if($this->con === null || $this->con === false){
- return 0;
- }
- return $this->con->insert_id;
- }
- public function real_escape_string($string){
- if($this->con === null || $this->con === false){
- return null;
- }
- return $this->con->real_escape_string($string);
- }
- public function affected_rows(){
- if($this->con === null || $this->con === false){
- return 0;
- }
- return $this->con->affected_rows;
- }
- public function error(){
- if($this->con === null || $this->con === false){
- return null;
- }
- return $this->con->error;
- }
- public function close(){
- if($this->con === null){
- return false;
- }
- $this->con->close();
- $this->con = null;
- return true;
- }
- public function __destruct(){
- $this->close();
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement