"; print_r($array); echo ""; } /* printLine function *\ prints a line of data/text \* */ function printLine($var) { echo $var.'
'; } function logLine($var) { global $doc_root; error_log( time().": ".$var."\n", 3, $doc_root."/log/debug.txt" ); } ?>__construct($host, $database, $name, $pass); } /* *\ php5 constructor \* */ function __construct($host, $database, $name, $pass) { $this->dbhost = $host; $this->dbdb = $database; $this->dbname = $name; $this->dbpass = $pass; } /* *\ database connection \* */ function dbConnect() { $dbCon = mysql_connect( $this->dbhost, $this->dbname, $this->dbpass ) or die("Failed to connect to MySQL server"); mysql_select_db( $this->dbdb, $dbCon ) or die("Failed to select MySQL database"); return $dbCon; } function dbClose () { mysql_close(); } function escape( $sString ) { return mysql_real_escape_string( $sString ); } /* *\ fetch_single_value usage: $var = fetch_single_value([field],[table],[where clause]); actual query: SELECT [field] FROM [table] WHERE [where clause] all three variables are needed. \* */ function fetch_single_value($field, $table, $where=false, $special=false) { $query = "SELECT {$field} FROM {$table}"; if ($where !== false) { $query .= " WHERE {$where}"; } if ($special !== false) { $query .= " ".$special; } $result = mysql_query( $query ); if (!$result) { printLine("Er is iets misgegaan, neem contact op met de beheerder, en voeg onderstaande foutmelding bij de communicatie.

".$query."

".mysql_error()); return false; } // support for field masking if (strpos($field,'AS') !== false) { $field = substr($field, strpos($field,'AS')+3); } // support for multi-table queries if (strpos($field,'.') !== false) { $field = substr($field, strpos($field,'.')+1); } if (mysql_num_rows($result) > 0) { $get = mysql_fetch_array($result); extract($get); } else { ${$field} = false; } // printLine("single: ".$query); return ${$field}; } /* *\ fetch_array_value usage: $array = fetch_array_value([field array],[table],[where clause],[order clause]); actual query: SELECT [field(s)] FROM [table(s)] WHERE [where clause] ORDER BY [order clause] only the first 2 variables are mandatory, the other 2 are optional. \* */ function fetch_array_value($array, $table, $where=false, $order=false) { $field = NULL; $arLen = count($array); for ($i=0;$i<$arLen;$i++) { $field .= $array[$i]; if ($i<$arLen-1) { $field.= ", "; } // support for field masking if (strpos($array[$i],'AS') !== false) { $array[$i] = substr($array[$i], strpos($array[$i],'AS')+3); } // support for multi-table queries if (strpos($array[$i],'.') !== false) { $array[$i] = substr($array[$i], strpos($array[$i],'.')+1); } } $query = "SELECT {$field} FROM {$table}"; if ($where !== false) { $query .= " WHERE {$where}"; } if ($order !== false) { if (strpos($order, "GROUP BY") !== false) { $query.= " ".$order; } else { $query.= " ORDER BY {$order}"; } } $c=0; $retArray = array(); $result = mysql_query($query); if (!$result) { printLine("Er is iets misgegaan, neem contact op met de beheerder, en voeg onderstaande foutmelding bij de communicatie.

".$query."

".mysql_error()); return false; } while ($get = mysql_fetch_array($result)) { extract($get); for ($t=0;$t<$arLen;$t++) { $retArray[$c][ $array[ $t ] ] = ${ $array[ $t ] }; } $c++; } // printLine("array: ".$query); return $retArray; } /* *\ dbQuery usage: dbQUery([action], [field array],[values array], [table],[where clause],[ok message], [not ok message]); actual query: depends on action all variables are mandatory. \* */ function dbQuery($action, $field, $value, $table, $where, $okmsg, $nokmsg, $ignore_quotes = false) { $numf = count($field); switch (strtoupper($action)) { case 'UPDATE': $query = "UPDATE ".$table; $query .= " SET "; for ($i=0;$i<$numf;$i++) { if( $ignore_quotes ) $query .= $field[$i]." = ".addslashes($value[$i]).""; else $query .= $field[$i]." = '".addslashes($value[$i])."'"; if ($i < $numf-1) { $query .= ", "; } } $query .= " WHERE ".$where; break; case 'INSERT': $fields = null; $values = null; $query = "INSERT INTO ".$table." ("; for ($i=0;$i<$numf;$i++) { $query .= $field[$i]; if ($i < $numf-1) { $query .= ", "; } } $query .= ") VALUES ("; for ($i=0;$i<$numf;$i++) { $query .= "'".addslashes($value[$i])."'"; if ($i < $numf-1) { $query .= ", "; } } $query .= ")"; break; case 'DELETE': $query = 'DELETE FROM '.$table.' WHERE '.$where; break; default: return "Er is geen geldige actie ingevoerd"; break; } // printLine($query); if (mysql_query($query)) { $message = $okmsg; } else { $message = $nokmsg."

".$query."

".mysql_error(); } return $message; } function runQuery( $query ) { if( mysql_query( $query ) ) return true; else return false; } } ?>