restore 2516 dbFacile.php, apparently the code layout changes breaking something somewhere?

git-svn-id: http://www.observium.org/svn/observer/trunk@2525 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Tom Laermans
2011-09-20 15:59:51 +00:00
parent 43f3c547b7
commit 3558ea53a0
4 changed files with 231 additions and 238 deletions
+1 -1
View File
@@ -161,7 +161,7 @@ if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format']))
$maptool = 'dot';
}
if ($where == '') { $maptool = 'neato -Gpack'; }
if ($where == '') { $maptool = 'sfdp -Gpack -Gcharset=latin1 -Gsize=200,200'; }
$img = shell_exec("echo \"".addslashes($map)."\" | $maptool -T".$_GET['format']."");
if ($_GET['format'] == "png")
+26 -33
View File
@@ -23,11 +23,10 @@ Usage
* */
function dbQuery($sql, $parameters = array()) {
global $fullSql, $debug;
$fullSql = dbMakeQuery($sql, $parameters);
if ($debug) { echo(" SQL[".$fullSql."] "); }
if($debug) { echo(" SQL[".$fullSql."] "); }
/*
if ($this->logFile)
if($this->logFile)
$time_start = microtime(true);
*/
@@ -35,13 +34,13 @@ function dbQuery($sql, $parameters = array()) {
$result = mysql_query($fullSql); // sets $this->result
/*
if ($this->logFile) {
if($this->logFile) {
$time_end = microtime(true);
fwrite($this->logFile, date('Y-m-d H:i:s') . "\n" . $fullSql . "\n" . number_format($time_end - $time_start, 8) . " seconds\n\n");
}
*/
if ($result === false && (error_reporting() & 1)) {
if($result === false && (error_reporting() & 1)) {
// aye. this gets triggers on duplicate Contact insert
//trigger_error('QDB - Error in query: ' . $fullSql . ' : ' . mysql_error(), E_USER_WARNING);
}
@@ -54,14 +53,12 @@ function dbQuery($sql, $parameters = array()) {
* */
function dbInsert($data, $table) {
global $fullSql;
global $db_stats;
// the following block swaps the parameters if they were given in the wrong order.
// it allows the method to work for those that would rather it (or expect it to)
// follow closer with SQL convention:
// insert into the TABLE this DATA
if (is_string($data) && is_array($table)) {
if(is_string($data) && is_array($table)) {
$tmp = $data;
$data = $table;
$table = $tmp;
@@ -73,12 +70,12 @@ function dbInsert($data, $table) {
$time_start = microtime(true);
dbBeginTransaction();
$result = dbQuery($sql, $data);
if ($result) {
if($result) {
$id = mysql_insert_id();
dbCommitTransaction();
#return $id;
} else {
if ($table != 'Contact') {
if($table != 'Contact') {
trigger_error('QDB - Insert failed.', E_USER_WARNING);
}
dbRollbackTransaction();
@@ -101,14 +98,12 @@ function dbInsert($data, $table) {
* */
function dbUpdate($data, $table, $where = null, $parameters = array()) {
global $fullSql;
global $db_stats;
// the following block swaps the parameters if they were given in the wrong order.
// it allows the method to work for those that would rather it (or expect it to)
// follow closer with SQL convention:
// update the TABLE with this DATA
if (is_string($data) && is_array($table)) {
if(is_string($data) && is_array($table)) {
$tmp = $data;
$data = $table;
$table = $tmp;
@@ -123,13 +118,13 @@ function dbUpdate($data, $table, $where = null, $parameters = array()) {
}
$sql = substr($sql, 0, -1); // strip off last comma
if ($where) {
if($where) {
$sql .= ' WHERE ' . $where;
$data = array_merge($data, $parameters);
}
$time_start = microtime(true);
if (dbQuery($sql, $data)) {
if(dbQuery($sql, $data)) {
$return = mysql_affected_rows();
} else {
#echo("$fullSql");
@@ -146,10 +141,10 @@ function dbUpdate($data, $table, $where = null, $parameters = array()) {
function dbDelete($table, $where = null, $parameters = array()) {
$sql = 'DELETE FROM `' . $table.'`';
if ($where) {
if($where) {
$sql .= ' WHERE ' . $where;
}
if (dbQuery($sql, $parameters)) {
if(dbQuery($sql, $parameters)) {
return mysql_affected_rows();
} else {
return false;
@@ -166,9 +161,9 @@ function dbFetchRows($sql, $parameters = array()) {
$time_start = microtime(true);
$result = dbQuery($sql, $parameters);
if (mysql_num_rows($result) > 0) {
if(mysql_num_rows($result) > 0) {
$rows = array();
while ($row = mysql_fetch_assoc($result)) {
while($row = mysql_fetch_assoc($result)) {
$rows[] = $row;
}
mysql_free_result($result);
@@ -194,7 +189,7 @@ function dbFetch($sql, $parameters = array()) {
/*
// for now, don't do the iterator thing
$result = dbQuery($sql, $parameters);
if ($result) {
if($result) {
// return new iterator
return new dbIterator($result);
} else {
@@ -212,7 +207,7 @@ function dbFetchRow($sql = null, $parameters = array()) {
$time_start = microtime(true);
$result = dbQuery($sql, $parameters);
if ($result) {
if($result) {
$row = mysql_fetch_assoc($result);
mysql_free_result($result);
$time_end = microtime(true);
@@ -233,10 +228,9 @@ function dbFetchRow($sql = null, $parameters = array()) {
* */
function dbFetchCell($sql, $parameters = array()) {
global $db_stats;
$time_start = microtime(true);
$row = dbFetchRow($sql, $parameters);
if ($row) {
if($row) {
return array_shift($row); // shift first field off first row
}
$time_end = microtime(true);
@@ -253,7 +247,6 @@ function dbFetchCell($sql, $parameters = array()) {
* */
function dbFetchColumn($sql, $parameters = array()) {
global $db_stats;
$time_start = microtime(true);
$cells = array();
foreach(dbFetch($sql, $parameters) as $row) {
@@ -276,7 +269,7 @@ function dbFetchKeyValue($sql, $parameters = array()) {
$data = array();
foreach(dbFetch($sql, $parameters) as $row) {
$key = array_shift($row);
if (sizeof($row) == 1) { // if there were only 2 fields in the result
if(sizeof($row) == 1) { // if there were only 2 fields in the result
// use the second for the value
$data[ $key ] = array_shift($row);
} else { // if more than 2 fields were fetched
@@ -293,7 +286,7 @@ function dbFetchKeyValue($sql, $parameters = array()) {
*/
function dbMakeQuery($sql, $parameters) {
// bypass extra logic if we have no parameters
if (sizeof($parameters) == 0)
if(sizeof($parameters) == 0)
return $sql;
$parameters = dbPrepareData($parameters);
@@ -301,7 +294,7 @@ function dbMakeQuery($sql, $parameters) {
$questionParams = array();
$namedParams = array();
foreach($parameters as $key => $value) {
if (is_numeric($key)) {
if(is_numeric($key)) {
$questionParams[] = $value;
} else {
$namedParams[ ':' . $key ] = $value;
@@ -320,9 +313,9 @@ function dbMakeQuery($sql, $parameters) {
$query .= $result[ $i ];
$j = $i+1;
if (array_key_exists($j, $result)) {
if(array_key_exists($j, $result)) {
$test = $result[ $j ];
if ($test == '?') {
if($test == '?') {
$query .= array_shift($questionParams);
} else {
$query .= $namedParams[ $test ];
@@ -341,7 +334,7 @@ function dbPrepareData($data) {
// don't quote or esc if value is an array, we treat it
// as a "decorator" that tells us not to escape the
// value contained in the array
if (is_array($value) && !is_object($value)) {
if(is_array($value) && !is_object($value)) {
$escape = false;
$value = array_shift($value);
}
@@ -349,7 +342,7 @@ function dbPrepareData($data) {
// that are aliases, or part of other tables through joins
//if(!in_array($key, $columns)) // skip invalid fields
// continue;
if ($escape) {
if($escape) {
$values[$key] = "'" . mysql_real_escape_string($value) . "'";
} else
$values[$key] = $value;
@@ -365,7 +358,7 @@ function dbPrepareData($data) {
function dbPlaceHolders($values) {
$data = array();
foreach($values as $key => $value) {
if (is_numeric($key))
if(is_numeric($key))
$data[] = '?';
else
$data[] = ':' . $key;
@@ -410,7 +403,7 @@ class dbIterator implements Iterator {
public function next() {
$this->i++;
$a = mysql_data_seek($this->result, $this->i);
if ($a === false) {
if($a === false) {
$this->i = 0;
}
return $a;
Regular → Executable
View File