I'm re-designing and re-writing all the back-end stuff that I use. I started with the way my framework (i guess?) works. Now that I have settled on the design of that, I decided to start re-writing the class that I do all my Database access stuff with.
I want to be able to run multiple queries at once. I remember someone saying that lack of support for multiple queries will hurt my sites performance or something. Why not pull everything at once?
So, I want to take some queries, the database name, and whatever values need to be, like so:
Code: Select all
$sql = array(
"INSERT INTO table1 (blah, dood, sup, lame, whoa) VALUES (null, '%s', '%s', '%s', '%s')",
"DELETE FROM table2 WHERE field1 = '%s'",
"SELECT * FROM table1 WHERE field1 = '%s'"
)
$db = array(
'whoa',
'dood',
'whoa'
)
$vals = array(
array(
'bro',
'chillin',
'word'
),
'no',
'yeah'
)Code: Select all
// Some hawt looking arrays or object, or both working together!Code: Select all
class DatabaseLayer
{
private $HOST;
private $USER;
private $PASS;
private $DBNAME;
public $mysql_link;
public $sql;
public $val;
public function __construct($host, $user, $pass)
{
$this->HOST = $host;
$this->USER = $user;
$this->PASS = $pass;
}
public function Connect()
{
$this->mysql_link = mysql_connect($this->HOST, $this->USER, $this->PASS);
}
public function Query($sql, $db, $vals = '')
{
$this->DBNAME = $db;
$this->sql = $sql;
$this->vals = $vals;
// I'm stuck here. I don't know what to do with this but I want to be able to run multiple queries in one go.
}
public function Disconnect()
{
mysql_close($this->mysql_link);
}
public function __destruct()
{
$this->Disconnect();
}
}If I can use objects how do I go about doing that? Do I need to write a new class to hold this information?
Would it be better just to use arrays?
Whenever I try to think about how to make this script work I get really lost inside my head. So I am here.
Comments, questions, suggestions?