function getSelectFrom($table, $fields, $keyvalues = array(), $clauses = '') { global $dbutils_show_errors; $qs = false; if (is_array($fields)) { // allow fields to be optional $clauses = $keyvalues; $keyvalues = $fields; $fields = '*'; } if ($clauses == '' && is_array($keyvalues) && count($keyvalues) == 0) { // allow overloading for simplest form: select('employee', 23) if (is_numeric($fields)) { $keyvalues = $fields; $fields = '*'; } } if (!is_array($keyvalues)) { $keyvalues = array('id' => 0 + @$keyvalues); } if (is_array($clauses)) { $clauses = qsafe($clauses); } if (count($keyvalues) > 0) { $qs = 'SELECT ' . $fields . ' FROM `' . $table . '` ' . ' WHERE (' . arraytosafe($keyvalues, true) . ') ' . $clauses; } else { if ($dbutils_show_errors) { echo 'No key/value given for select.' . "\r\n"; } die; } return $qs; }
function getSelectFrom($table, $fields, $keyvalues = array(), $clauses = '', $stack_trace_level = 0) { global $dbutils_show_errors; if ('' . @$table == '') { dbiutils_stack_trace('No table specified', $stack_trace_level); return false; } $qs = false; if (is_array($fields)) { // allow fields to be optional $clauses = $keyvalues; $keyvalues = $fields; $fields = '*'; } if ($clauses == '' && is_array($keyvalues) && count($keyvalues) == 0) { // allow overloading for simplest form: select('employee', 23) if (is_numeric($fields)) { $keyvalues = $fields; $fields = '*'; } } if (!is_array($keyvalues)) { $keyvalues = array('id' => 0 + @$keyvalues); } if (is_array($clauses)) { $clauses = qsafe($clauses, 1 + @$stack_trace_level); } if (count($keyvalues) > 0) { $qs = 'SELECT ' . $fields . ' FROM `' . $table . '` ' . ' WHERE (' . arraytosafe($keyvalues, true) . ') ' . $clauses; } else { dbiutils_stack_trace('No match criteria specified', $stack_trace_level); return false; // changed from die() to be more consistent } return $qs; }