Home
Scripts
Tutorials
Blogs
Smart Home
Script Collections
Tutorials
Contact
Tutorials
Creating a simple DbManager in PHP
function MysqlManager()
{
//Initializing Mysql Manager //
$this->QueryString = '';
$this->QueryResult = '';
$this->QueryRows = '';
$this->QueryError = '';
$this->DbUser = "root"; //server auth user //
$this->DbPass = ""; //server auth pass //
$this->DbHost = "localhost"; //server address //
$this->DbName = "folklore"; //
$this->field_count = 0;
$this->row_count = 0;
}
function _connect_mysql()
{
$this->DbCon = @mysql_connect($this->DbHost,$this->DbUser,$this->DbPass); //Conect Myql Server //
if(!$this->DbCon)
{
$this->_mysql_error(mysql_error());
}
else
{
$this->_select_database();
}
}
//Now select database for the application//
function _select_database()
{
if(empty($this->DbName))
{
$this->_mysql_error("Database Name Empty ");
}
else
{
$db = @mysql_select_db($this->DbName);
if(!$db)
{
$this->_mysql_error("Cannot Find the Database ");
}
}
}
//execute Query section //
function _exec_query($query)
{
$this->QueryString = $query;
$this->QueryResult = @mysql_query($this->QueryString);
if(!$this->QueryResult)
{
//
$this->_mysql_error(mysql_error());
return false;
}
else
{
return true;
}
}
Download complete source code
Back to Index