44 function DBconnect($sysconfdir, $options=
"", $exitOnFail=
true)
48 if (! empty($PG_CONN)) {
52 $path=
"$sysconfdir/Db.conf";
53 if (empty($options)) {
54 $dbConf = file_get_contents($path);
55 if ($exitOnFail && (
false === $dbConf)) {
56 $text = _(
"Could not connect to FOSSology database.");
57 echo
"<h2>$text</h2>";
58 echo _(
'permission denied for configuration file');
61 if (
false === $dbConf) {
67 if (! empty($options)) {
68 $PG_CONN = pg_connect(str_replace(
";",
" ", $options));
71 if (! empty($PG_CONN)) {
77 $text = _(
"Could not connect to FOSSology database.");
78 echo
"<h2>$text</h2>";
106 $sql =
"SELECT * from $Table $Where limit 1";
107 $result = pg_query($PG_CONN, $sql);
110 $row = pg_fetch_assoc($result);
111 pg_free_result($result);
138 $sql =
"SELECT $KeyCol, $ValCol from $Table $Where";
139 $result = pg_query($PG_CONN, $sql);
142 while ($row = pg_fetch_assoc($result)) {
143 $ResArray[$row[$KeyCol]] = $row[$ValCol];
171 $sql =
"SELECT DISTINCT $ValCol from $Table $Where";
173 $sql =
"SELECT $ValCol from $Table $Where";
175 $result = pg_query($PG_CONN, $sql);
179 while ($row = pg_fetch_assoc($result)) {
180 $ResArray[$i] = $row[$ValCol];
203 echo
"<hr>File: $filenm, Line number: $lineno<br>";
204 if (pg_connection_status($PG_CONN) === PGSQL_CONNECTION_OK) {
205 echo pg_last_error($PG_CONN);
207 echo
"FATAL: DB connection lost.";
230 $sql =
"select count(*) as count from information_schema.tables where " 231 .
"table_catalog='{$SysConf['DBCONF']['dbname']}' and table_name='$tableName'";
232 $result = pg_query($PG_CONN, $sql);
234 $row = pg_fetch_assoc($result);
235 $count = $row[
'count'];
236 pg_free_result($result);
255 $sql =
"select count(*) as count from information_schema.columns where " 256 .
"table_catalog='$DBName' and table_name='$tableName' and column_name='$colName'";
257 $result = pg_query($PG_CONN, $sql);
259 $row = pg_fetch_assoc($result);
260 $count = $row[
'count'];
261 pg_free_result($result);
279 $sql =
"select count(*) as count from information_schema.table_constraints " 280 .
"where table_catalog='$DBName' and constraint_name='$ConstraintName' limit 1";
281 $result = pg_query($PG_CONN, $sql);
283 $row = pg_fetch_assoc($result);
284 $count = $row[
'count'];
285 pg_free_result($result);
308 $sql =
"SELECT currval('$seqname') as mykey FROM $tablename";
309 $result = pg_query($PG_CONN, $sql);
311 $row = pg_fetch_assoc($result);
312 $mykey = $row[
"mykey"];
313 pg_free_result($result);
DBconnect($sysconfdir, $options="", $exitOnFail=true)
Connect to database engine. This is a no-op if $PG_CONN already has a value.
GetLastSeq($seqname, $tablename)
Get last sequence number.
GetSingleRec($Table, $Where="")
Retrieve a single database record.
DB2ValArray($Table, $ValCol, $Uniq=false, $Where="")
Create an array by using table rows to source the values.
DB_TableExists($tableName)
Check if table exists.
DB_ConstraintExists($ConstraintName, $DBName='fossology')
Check if a constraint exists.
DB2KeyValArray($Table, $KeyCol, $ValCol, $Where="")
Create an associative array by using table rows to source the key/value pairs.
DB_ColExists($tableName, $colName, $DBName='fossology')
Check if a column exists.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
debugbacktrace()
Debug back trace.