Web Development, SEO, Social Media, Software & Database Development
PHP MySQL Connect with OOP
Simple connector using a constructor with in the class, I intend to add to this in later examples.
------------------CODE--------------------------
<?php
class DbConnect
{
function __construct($host,$username,$password)
{
$this->connect($host,$username,$password);
}
function connect ($host,$username,$password)
{
$con =mysql_connect($host,$username,$password);
if(!$con)
{
die('Could not connect: ' . mysql_error());
}
}
}
$DatabaseConnection = new DbConnect("localhost","root","");
?>
Labels:
function __construct,
MySQL,
mysql_connect,
OOP,
PHP
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment