Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $servername = "ejemplo.es";
- $username = "ramon";
- $dbname = "bbdd";
- $password = "loquesea";
- $conn = new mysqli($servername, $username, $password, $dbname);
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- <?php
- class Database
- {
- private $_connection = null;
- public function __construct($host, $username, $password, $database)
- {
- // connect to database and store the connection for further use
- }
- public function doThisAndThat()
- {
- // do some fancy database stuff
- }
- public function __destruct()
- {
- // important for databases is to disconnect from them
- }
- }
- $db = new Database($host, $username, $password, $database);
- $db->doThisAndThat();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement