// SELECTS A DB IF NOT SPECIFIED ABOVE public function dbSelect($dbSelect) { $this->db_name = $dbSelect; $this->connect(); }
// GET VAR, ESCAPES THE STRING, EXEC QUERY, SETS RESULT public function query($query) { $query = mysql_escape_string($query); $q = mysql_query("$query");
if ($q) { return true; } else { return false; } }
// FETCHES QUERY ROWS FROM DB public function fetch($query) { $query = mysql_escape_string($query); $q = mysql_query("$query");
Why dont you try changing your class so that it works something like this:
PHP Code:
//syntax is a little complicated //feel free to create your own! $db->query(array( "type"=>"select", "attribs"=>array( "table"=>'users', "fields"=>array('name','surname','id_number','cellphone'), "conditions"=>array("name"=>"='john'","surname"=>"='doe'"), "limit"=>array(0,30), "order"=>array("name"=>'d',surname=>'a') ))); //then you get your class to format it like this: SELECT name,surname,id_number,cellphone FROM users WHERE name='john' AND surname = 'doe' ORDER BY name ASC, surname DESC LIMIT 0,30;
That way, and this is just a suggestion, you can make your class cross-database-type compatible and its a nice challenge!
require_once('cls/query.php'); // YOU CAN USE INCLUDE IF YOU WISH
$q = new Mysql();
$q->query($dataSelect); // DATA FROM ARRAY ABOVE GETS PASSED TO FUNCTION
$q->query($dataUpdate); // DATA FROM ARRAY ABOVE GETS PASSED TO FUNCTION
$q->query($dataDelete); // DATA FROM ARRAY ABOVE GETS PASSED TO FUNCTION
$q->query($dataInsert); // DATA FROM ARRAY ABOVE GETS PASSED TO FUNCTION
$nrows = $q->getNumRow(); // IF YOU WERE COUNTING NUM ROWS
$r = $q->getResults(); // IF YOU WERE PULLING DATA FROM DB
apologise for the horrid array indents they looked fine in the editor