Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Connection {
- private static $DB_HOST = 'fenrir.info.uaic.ro';
- private static $DB_NAME = 'twebDB';
- private static $DB_USER = 'twebDB';
- private static $DB_PASS = 'MtFjuUtw2J';
- private static $dbInstance;
- private function __construct() {}
- public static function openConnection() {
- if(!isset(self::$dbInstance)) {
- // instantiem obiectul MySQL, via constructorul care va realiza conectarea la serverul MySQL
- $conn = new mysqli (
- self::$DB_HOST, // locatia serverului (aici, masina locala)
- self::$DB_USER, // numele de cont
- self::$DB_PASS, // parola (atentie, in clar!)
- self::$DB_NAME // baza de date
- );
- if($conn->connect_error) {
- header("Location: notfound.php");
- die();
- }
- }
- }
- public static function closeConnection() {
- if(isset(self::$dbInstance)) {
- self::$dbInstance->close();
- self::$dbInstance = null;
- }
- }
- // inchidem conexiunea cu serverul MySQL
- //mysqli_close($mysql);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement