Last active
February 11, 2016 19:19
-
-
Save natanverdes/9add27cda6ce2bd6ba7b to your computer and use it in GitHub Desktop.
MySQL PHP Connection Manager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DBConnection{ | |
private static $DB_SERVER = "localhost"; | |
private static $DB_USER = "root"; | |
private static $DB_PASS = ""; | |
private static $DB_NAME = "db_name"; | |
private $con; | |
private $result; | |
private $numRows; | |
public function __construct(){ | |
$this->con = new mysqli(self::$DB_SERVER, self::$DB_USER, self::$DB_PASS, self::$DB_NAME); | |
if ( $this->_db->connect_errno ){ | |
echo "Connection error"; | |
return; | |
} | |
$this->con->query("SET NAMES 'UTF8'"); | |
$this->con->set_charset('utf-8'); | |
} | |
public function __destruct(){ | |
$this->con->close(); | |
} | |
public function executer($sql){ | |
$this->result = $this->con->query($sql); | |
$this->numRows = $this->result->num_rows; | |
} | |
public function getNumRows(){ | |
return $this->numRows; | |
} | |
public function getResultados(){ | |
$rows = array(); | |
for($i=0;$i<$this->numRows; $i++){ | |
$rows[] = $this->result->fetch_assoc(); | |
} | |
return $rows; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment