Created
March 19, 2013 15:38
-
-
Save tjFogarty/5197131 to your computer and use it in GitHub Desktop.
Quick and simple database connection
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
<?php | |
include('db.class.php'); | |
$database = new Database(); | |
$database->dbUrl = 'localhost'; //URL of database | |
$database->dbUser = 'root'; // Username | |
$database->dbPass = ''; // Password | |
$database->dbName = 'test_db'; // Name of database you wish to connect to | |
$database->connect(); |
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
<?php | |
class Database { | |
public $dbUrl; | |
public $dbUser; | |
public $dbPass; | |
public $dbName; | |
public $dbTable; | |
public function connect() { | |
$con = mysql_connect( $this->dbUrl, $this->dbUser, $this->dbPass ); | |
if( !$con ) die( "Could not connect: " . mysql_error() ); | |
mysql_select_db( $this->dbName ) or die( "Could not connect to database: " + mysql_error() ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment