13 * Protect password from the global space
15 function db_set_active() {
19 if (!$db['conn'] = mysql_connect($db['host'], $db['user'], $db['pwd'])) {
20 echo 'Could not connect to mysql';
24 if (!mysql_select_db($db['db'], $db['conn'])) {
25 echo 'Could not select database';
34 function db_unpack(&$data){
36 foreach($data as $key => $k){
44 * Sends a db query and replaces tables with their appropriate names
47 * The query to be excecuted
49 * If you want the system to unpack the results calling db_unpack
51 * If you are expecting or want to reinforce to only receive one row
53 * For paged queries, not yet implemented
57 * mysql_affected_rows and mysql_num_rows are not properly working
59 function db_query($query, $unpack = FALSE, $single = FALSE, $pager = FALSE){
65 if($query == 'DEBUG'){
70 if(core_variable_get('debug_info', 'No') == 'Yes'){
78 $db['query'] = str_replace('{PRE_}', $db['pre'], $query);
81 $q = mysql_query($db['query'], $db['conn']);
83 $db['num_rows'] = @mysql_num_rows($q);
85 $db['error'] = mysql_error();
87 $db['affected_rows'] = mysql_affected_rows();
89 $error_display = core_variable_get('db_errors', 'Database Only');
92 if($error_display == 'Screen Only' || $error_display == 'Screen and Database'){
93 system_warnings($db['error'], 'error');
94 system_warnings($db['query'], 'error');
100 elseif($db['affected_rows'] > 0){
101 if($db['num_rows'] > 0){
102 while($item = mysql_fetch_assoc($q)){
107 foreach($results as $result){
108 $row[] = db_unpack($result);
111 if(count($row) == 1 && $single){
122 //in case of non-select queries