diff options
| author | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2002-06-17 06:27:32 +0000 |
|---|---|---|
| committer | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2002-06-17 06:27:32 +0000 |
| commit | 043dbb70cbc557bbc5f70a74453e506546148963 (patch) | |
| tree | 9dcdd9364879c4ac3384d4e53b2054653964a69b /frontends/php/include/db.inc.php | |
| parent | 565fba506fd51acbedc8d06c07b93abae22444a7 (diff) | |
- php/include/*inc renamed to php/include/*inc.php (Alexei)
- check of source IP address for trapped values (Alexei)
- added include/security.h and include/security.c (Alexei)
- added items.trapper_hosts (Alexei)
git-svn-id: svn://svn.zabbix.com/trunk@411 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include/db.inc.php')
| -rw-r--r-- | frontends/php/include/db.inc.php | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/frontends/php/include/db.inc.php b/frontends/php/include/db.inc.php new file mode 100644 index 00000000..2de3acce --- /dev/null +++ b/frontends/php/include/db.inc.php @@ -0,0 +1,135 @@ +<? + +// $DB_TYPE ="POSTGRESQL"; + $DB_TYPE ="MYSQL"; + $DB_SERVER ="localhost"; + $DB_DATABASE ="zabbix"; +// $DB_USER ="zabbix"; + $DB_USER ="root"; + $DB_PASSWORD =""; + + $USER_DETAILS =""; + + if($DB_TYPE == "MYSQL") + { + $DB=mysql_pconnect($DB_SERVER,$DB_USER,$DB_PASSWORD); + mysql_select_db($DB_DATABASE); + } + if($DB_TYPE == "POSTGRESQL") + { + $DB=pg_pconnect("host=$DB_SERVER dbname=$DB_DATABASE user=$DB_USER password=$DB_PASSWORD"); + if(!$DB) + { + echo "Error connecting to database"; + exit; + } + } + + function DBselect($query) + { + global $DB,$DB_TYPE; + +// echo $query,"<br>"; + + if($DB_TYPE == "MYSQL") + { + $result=mysql_query($query,$DB); + return $result; + } + if($DB_TYPE == "POSTGRESQL") + { + $result=pg_exec($DB,$query); + return $result; + } + } + + function DBexecute($query) + { + global $DB,$DB_TYPE; + +// echo $query,"<br>"; + + if($DB_TYPE == "MYSQL") + { + $result=mysql_query($query,$DB); + return $result; + } + if($DB_TYPE == "POSTGRESQL") + { + $result=pg_exec($DB,$query); + return $result; + } + } + + function DBfetch($result) + { + global $DB_TYPE; + + if($DB_TYPE == "MYSQL") + { + $row=mysql_fetch_array($result); + return $row; + } + if($DB_TYPE == "POSTGRESQL") + { + $row=pg_fetch_array($result); + return $row; + } + } + + function DBget_field($result,$rownum,$fieldnum) + { + global $DB_TYPE; + + if($DB_TYPE == "MYSQL") + { + mysql_data_seek($result,$rownum); + $row=mysql_fetch_row($result); + return $row[$fieldnum]; + } + if($DB_TYPE == "POSTGRESQL") + { + $row=pg_fetch_row($result,$rownum); + if(!$row) + { + echo "Error getting row"; + exit; + } + return $row[$fieldnum]; + } + } + + function DBnum_rows($result) + { + global $DB_TYPE; + + if($DB_TYPE == "MYSQL") + { + return mysql_num_rows($result); + } + if($DB_TYPE == "POSTGRESQL") + { + return pg_numrows($result); + } + } + + function DBinsert_id($result,$table,$field) + { + global $DB,$DB_TYPE; + + if($DB_TYPE == "MYSQL") + { + return mysql_insert_id($DB); + } + + if($DB_TYPE == "POSTGRESQL") + { + $oid=pg_getlastoid($result); +// echo "OID:$oid<br>"; + $sql="select $field from $table where oid=$oid"; + $result=DBselect($sql); + return DBget_field($result,0,0); + } + } + +?> |
