function select($cmd) { $rtn = null; do_pg_connect(); debug("\nSQL: {$cmd}\n"); if (!($result = pg_query($cmd))) { $out = "\nSQL QUERY: " . $cmd . "\nSQL ERROR: " . pg_last_error() . "\nSQL ERROR: " . pg_result_error(); mtt_error($out); mtt_send_mail($out); } $rtn = pg_fetch_all($result); if (false == $rtn) { return array(); } else { return $rtn; } }
function get_serial() { $error_function = "get_serial()"; # Works in psql cli, *BROKEN* in php # $cmd = "\n SELECT relname FROM pg_class WHERE " . # "\n\t relkind = 'S' AND " . # "\n\t relnamespace IN ( " . # "\n\t SELECT oid FROM pg_namespace WHERE " . # "\n\t nspname NOT LIKE 'pg_%' AND " . # "\n\t nspname != 'information_schema') " . # "\n\t AND relname NOT LIKE '%id_seq';"; # # $serial_name = select_scalar($cmd); $serial_name = 'client_serial'; $serial = fetch_single_nextval($serial_name); if (NULL == $serial) { $error_output = "CRITICAL ERROR: Cannot continue\n" . "-------------------------------\n" . "Failed to find a ({$serial_name}) value!\n" . "-------------------------------\n"; mtt_send_mail($error_output, $error_function); mtt_abort(400, $error_output); exit(1); } return $serial; }