Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Perform a MySQL Query.
- function query($what,$from,$where = NULL,$orderBy = NULL) {
- // Create the beginning string.
- $select = 'SELECT '.$what.' FROM '.$from.' ';
- // Set a variable to 0.
- $i = 1;
- // If there ar where statements...
- if(!empty($where)) {
- // Add WHERE to the select.
- $select .= "WHERE ";
- // For every WHERE statement...
- foreach($where as $key => $value) {
- // Add on to the string.
- $select .= $key.'="'.$value.'" ';
- // Get the number of array objects.
- $count = count($where);
- // If the count is not the last item in the array...
- if($i < $count) {
- // Then add an AND!
- $select .= ' AND ';
- }
- // Increase i by 1.
- $i++;
- }
- }
- // If there is an order...
- if(!empty($orderBy)) {
- $select .= "ORDER BY ".$orderBy;
- }
- // Filter the select.
- $selectFiltered = mysql_real_escape_string($select);
- // Attempt the query.
- $query = mysql_query($select);
- // If it fails...
- if(!$query) {
- // Output an error.
- $this->primary->errorMsg('MySQL Error','A MySQL Error occured trying to process the query "'.$selectFiltered.'". The system cannot continue.');
- }
- return $query;
- }
Add Comment
Please, Sign In to add comment