33 function DBconnect($sysconfdir, $options=
"", $exitOnFail=
true)
41 $path=
"$sysconfdir/Db.conf";
42 if (empty($options)) {
43 $dbConf = file_get_contents($path);
44 if ($exitOnFail && (
false === $dbConf)) {
45 $text = _(
"Could not connect to FOSSology database.");
46 echo
"<h2>$text</h2>";
47 echo _(
'permission denied for configuration file');
50 if (
false === $dbConf) {
56 if (! empty($options)) {
57 $PG_CONN = pg_connect(str_replace(
";",
" ", $options));
66 $text = _(
"Could not connect to FOSSology database.");
67 echo
"<h2>$text</h2>";
95 $sql =
"SELECT * from $Table $Where limit 1";
99 $row = pg_fetch_assoc($result);
100 pg_free_result($result);
127 $sql =
"SELECT $KeyCol, $ValCol from $Table $Where";
131 while ($row = pg_fetch_assoc($result)) {
132 $ResArray[$row[$KeyCol]] = $row[$ValCol];
160 $sql =
"SELECT DISTINCT $ValCol from $Table $Where";
162 $sql =
"SELECT $ValCol from $Table $Where";
168 while ($row = pg_fetch_assoc($result)) {
169 $ResArray[$i] = $row[$ValCol];
192 echo
"<hr>File: $filenm, Line number: $lineno<br>";
193 if (pg_connection_status(
$PG_CONN) === PGSQL_CONNECTION_OK) {
196 echo
"FATAL: DB connection lost.";
198 echo
"<br> ".htmlspecialchars($sql);
219 $sql =
"select count(*) as count from information_schema.tables where "
220 .
"table_catalog='{$SysConf['DBCONF']['dbname']}' and table_name='$tableName'";
223 $row = pg_fetch_assoc($result);
224 $count = $row[
'count'];
225 pg_free_result($result);
244 $sql =
"select count(*) as count from information_schema.columns where "
245 .
"table_catalog='$DBName' and table_name='$tableName' and column_name='$colName'";
248 $row = pg_fetch_assoc($result);
249 $count = $row[
'count'];
250 pg_free_result($result);
268 $sql =
"select count(*) as count from information_schema.table_constraints "
269 .
"where table_catalog='$DBName' and constraint_name='$ConstraintName' limit 1";
272 $row = pg_fetch_assoc($result);
273 $count = $row[
'count'];
274 pg_free_result($result);
297 $sql =
"SELECT currval('$seqname') as mykey FROM $tablename";
300 $row = pg_fetch_assoc($result);
301 $mykey = $row[
"mykey"];
302 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.
DB_ColExists($tableName, $colName, $DBName='fossology')
Check if a column exists.
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
GetLastSeq($seqname, $tablename)
Get last sequence number.
DB_ConstraintExists($ConstraintName, $DBName='fossology')
Check if a constraint exists.
GetSingleRec($Table, $Where="")
Retrieve a single database record.
DB_TableExists($tableName)
Check if table exists.
DB2KeyValArray($Table, $KeyCol, $ValCol, $Where="")
Create an associative array by using table rows to source the key/value pairs.
DB2ValArray($Table, $ValCol, $Uniq=false, $Where="")
Create an array by using table rows to source the values.
debugbacktrace()
Debug back trace.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN