-
-
Save adorilson/131091bc3c83c0af49e6 to your computer and use it in GitHub Desktop.
Database Connection PHP using the class PDO.
This file contains hidden or 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
| <?php | |
| class Connection | |
| { | |
| public static $db; | |
| private static function doConnection() | |
| { | |
| if (!isset(self::$db)) { | |
| try { | |
| $host = "YOUR_HOST"; | |
| $db_name = "YOUR_DB"; | |
| $user = "YOUR_USER"; | |
| $pass = "YOUR_PASS"; | |
| self::$db = new PDO("mysql:host=$host;dbname=$db_name", $user, $pass); | |
| self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
| self::$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ); | |
| } | |
| catch (PDOException $e) { | |
| echo "CONNECTION ERRO" . $e->getMessage(); | |
| } | |
| } | |
| return self::$db; | |
| } | |
| //ISSO AQUI NUM TEM NADA A VER | |
| public static function prepare($sql) | |
| { | |
| return self::doConnection()->prepare($sql); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks...