I'm trying to make a generic function to run queries with Pear MDB2, (autoExecute)
The two functions belowe works, the sql would is SELECT ... FROM ... WHERE settings_active = foo AND settings_level = bar,
Is it possible to use the select function to make use of more statements in the where part of the sql query? for example use of OR, GREATER etc.?
function select( $table_name, $result_types, $where ){
global $dbprefix;
$table_name = $dbprefix . $table_name;
$this->mdb2->loadModule('Extended');
$result = $this->mdb2->extended->autoExecute(
$table_name,
null,
MDB2_AUTOQUERY_SELECT,
$where,
null,
true,
$result_types
);
if (PEAR::isError($result)) {
die($result->getMessage());
}
return $result;
}
function getAllSettingsSQL(){
$table_name = "settings";
$result_types = array (
'settings_ID' => 'integer',
'settings_name' => 'text',
'settings_desc' => 'text',
'settings_active' => 'text',
'settings_value' => 'text',
'settings_level' => 'integer'
);
$where = array(
'settings_active' => $this->mdb2->quote('1', 'text'),
'settings_level' => $this->mdb2->quote(3, 'integer'),
);
$result = $this->select($table_name, $result_types, $where);
$data = array();
while($row = $result->fetchRow()){
echo "<p>". $row['settings_name'] . " - ". $row['settings_value'] ."</p>";
}
}
Or do I have to alter the select function to take a sql query as parameter and use standard prepare and execute.
by: German_RummPosted on 2007-02-28 at 09:22:12ID: 18626868
As far as I know, $where argument for autoExecute() should be a string.
$result_types, $where);
So you should basically compose your own $where string and pass it to autoExecute().
Example:
$where = '(Age BETWEEN 18 AND 25) OR Height > 160';
$this->select($table_name,