function sync_object($object_type, $object_name) { # Should only provide error information on stderr: put stdout to syslog $cmd = "geni-sync-wireless {$object_type} {$object_name}"; error_log("SYNC(cmd) " . $cmd); $descriptors = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w")); $process = proc_open($cmd, $descriptors, $pipes); $std_output = stream_get_contents($pipes[1]); # Should be empty $err_output = stream_get_contents($pipes[2]); fclose($pipes[1]); fclose($pipes[2]); $proc_value = proc_close($process); $full_output = $std_output . $err_output; foreach (split("\n", $full_output) as $line) { if (strlen(trim($line)) == 0) { continue; } error_log("SYNC(output) " . $line); } if ($proc_value != RESPONSE_ERROR::NONE) { error_log("WIRELESS SYNC error: {$proc_value}"); } return $proc_value; }
/** * * @param array $current_import * @return bool */ function import(array $current_import) { // fetch the remote content $html = wp_remote_get($current_import['file']); // Something failed if (is_wp_error($html)) { $redirect_url = get_admin_url(get_current_blog_id(), '/tools.php?page=pb_import'); error_log('\\PressBooks\\Import\\Html import error, wp_remote_get() ' . $html->get_error_message()); $_SESSION['pb_errors'][] = $html->get_error_message(); $this->revokeCurrentImport(); \Pressbooks\Redirect\location($redirect_url); } $url = parse_url($current_import['file']); // get parent directory (with forward slash e.g. /parent) $path = dirname($url['path']); $domain = $url['scheme'] . '://' . $url['host'] . $path; // get id (there will be only one) $id = array_keys($current_import['chapters']); // front-matter, chapter, or back-matter $post_type = $this->determinePostType($id[0]); $chapter_parent = $this->getChapterParent(); $body = $this->kneadandInsert($html['body'], $post_type, $chapter_parent, $domain); // Done return $this->revokeCurrentImport(); }
public function cpanel() { $whmusername = "******"; $whmhash = "somelonghash"; # some hash value $query = "https://127.0.0.1:2087/...."; $curl = curl_init(); # Create Curl Object curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); # Allow certs that do not match the domain curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); # Allow self-signed certs curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); # Return contents of transfer on curl_exec $header[0] = "Authorization: WHM {$whmusername}:" . preg_replace("'(\r|\n)'", "", $whmhash); # Remove newlines from the hash curl_setopt($curl, CURLOPT_HTTPHEADER, $header); # Set curl header curl_setopt($curl, CURLOPT_URL, $query); # Set your URL $result = curl_exec($curl); # Execute Query, assign to $result if ($result == false) { error_log("curl_exec threw error \"" . curl_error($curl) . "\" for {$query}"); } curl_close($curl); print $result; }
/** * Remove the record IF there are no records referencing this user. */ function updateDatabase($form, $myvalues) { //Perform some data quality checks now. if (!isset($myvalues['protocol_shortname'])) { die("Cannot delete record because missing protocol_shortname in array!\n" . var_dump($myvalues)); } $updated_dt = date("Y-m-d H:i", time()); $protocol_shortname = $myvalues['protocol_shortname']; //Backup all the existing records. $this->m_oPageHelper->copyProtocolLibToReplacedTable($protocol_shortname); $this->m_oPageHelper->copyKeywordsToReplacedTable($protocol_shortname); $this->m_oPageHelper->copyTemplateValuesToReplacedTable($protocol_shortname); //Delete all the records. $num_deleted = db_delete('raptor_protocol_lib')->condition('protocol_shortname', $protocol_shortname)->execute(); $num_deleted = db_delete('raptor_protocol_keywords')->condition('protocol_shortname', $protocol_shortname)->execute(); $num_deleted = db_delete('raptor_protocol_template')->condition('protocol_shortname', $protocol_shortname)->execute(); //Success? if ($num_deleted == 1) { $feedback = 'The ' . $protocol_shortname . ' protocol has been succesfully deleted.'; drupal_set_message($feedback); return 1; } //We are here because we failed. $feedback = 'Trouble deleting ' . $protocol_shortname . ' protocol!'; error_log($feedback . ' delete reported ' . $num_deleted); drupal_set_message($feedback, 'warning'); return 0; }
/** * Prints the stack trace for this exception. */ public function printStackTrace() { if (null === $this->wrappedException) { $this->setWrappedException($this); } $exception = $this->wrappedException; if (!sfConfig::get('sf_test')) { // log all exceptions in php log error_log($exception->getMessage()); // clean current output buffer while (ob_get_level()) { if (!ob_end_clean()) { break; } } ob_start(sfConfig::get('sf_compressed') ? 'ob_gzhandler' : ''); header('HTTP/1.0 500 Internal Server Error'); } try { $this->outputStackTrace($exception); } catch (Exception $e) { } if (!sfConfig::get('sf_test')) { exit(1); } }
/** * SetLogFiles */ function GoogleLog($errorLogFile, $messageLogFile, $logLevel = L_ERR_RQST, $die = true) { $this->logLevel = $logLevel; if ($logLevel == L_OFF) { $this->logLevel = L_OFF; } else { if (!($this->errorLogFile = @fopen($errorLogFile, "a"))) { header('HTTP/1.0 500 Internal Server Error'); $log = "Cannot open " . $errorLogFile . " file.\n" . "Logs are not writable, set them to 777"; error_log($log, 0); if ($die) { die($log); } else { echo $log; $this->logLevel = L_OFF; } } if (!($this->messageLogFile = @fopen($messageLogFile, "a"))) { fclose($this->errorLogFile); header('HTTP/1.0 500 Internal Server Error'); $log = "Cannot open " . $messageLogFile . " file.\n" . "Logs are not writable, set them to 777"; error_log($log, 0); if ($die) { die($log); } else { echo $log; $this->logLevel = L_OFF; } } } $this->logLevel = $logLevel; }
protected function prepareSubmitData($key) { $var = $this->getArg($key, array()); if (!$type = $this->getArg('_type')) { error_log("Type data not found"); return $var; } if (!is_array($var)) { $type = isset($type[$key]) ? $type[$key] : null; return $this->prepareSubmitValue($var, $type); } elseif (!isset($type[$key])) { error_log("Type data not found for $key"); return $var; } $types = $type[$key]; foreach ($types as $key=>$type) { if (is_array($type)) { foreach ($type as $_key=>$_type) { $value = isset($var[$key][$_key]) ? $var[$key][$_key] : null; $var[$key][$_key] = $this->prepareSubmitValue($value, $_type); } } else { $value = isset($var[$key]) ? $var[$key] : null; $var[$key] = $this->prepareSubmitValue($value, $type); } } return $var; }
public function service($request, $response) {/*{{{*/ ob_start(); $result = $this->callCenterApi->returnSuccess(); $function = $request->service; if(method_exists($this, $function)) { try { $lockName = $this->getLockerName($request); $cacher= DAL::get()->getCache(Cacher::CACHETYPE_LOCKER); $locker = LockUtil::factory(LockUtil::LOCK_TYPE_MEMCACHE, array('memcache' => $cacher)); $locker->getLock($lockName); $result = $this->$function($request,$response); $locker->releaseLock($lockName); } catch(LockException $ex) { error_log(XDateTime::now()->toString()."并发锁错误 $lockName\n", 3 , $this->logFileName); } catch(Exception $ex) { error_log(XDateTime::now()->toString()."释放锁 $lockName\n", 3 , $this->logFileName); $locker->releaseLock($lockName); } } echo $result; $this->logTxt .= XDateTime::now()->toString().'--->'.print_r($result, true)."\n"; header('Content-Length: ' . ob_get_length()); return parent::DIRECT_OUTPUT; }/*}}}*/
/** * Formatea y guarda el mensaje en el archivo de log. Además se le agrega la fecha y hora * y un salto de linea * * @access public * @param $message (string) mensaje a logear * @return void */ function log2file($message) { // Agregar la fecha y hora en la cual ocurrió en error $fecha = date('d/m/Y H:i:s'); $message = $fecha . ';' . $message . "\r\n"; error_log($message, 3, $this->filename); }
function raise($e_message) { global $page; array_push($this->e_list, $e_message); error_log("StreamOnTheFly error: $msg", 0); $page->halt(); exit; }
public static function log_errors($msg = null, $strip = false) { if (defined('LOG_XPM4_ERRORS')) { if (is_string(LOG_XPM4_ERRORS) && is_string($msg) && is_bool($strip)) { if (is_array($arr = unserialize(LOG_XPM4_ERRORS)) && isset($arr['type']) && is_int($arr['type']) && ($arr['type'] == 0 || $arr['type'] == 1 || $arr['type'] == 3)) { $msg = "\r\n" . '[' . date('m-d-Y H:i:s') . '] XPM4 ' . ($strip ? str_replace(array('<br />', '<b>', '</b>', "\r\n"), '', $msg) : $msg); if ($arr['type'] == 0) { error_log($msg); } else { if ($arr['type'] == 1 && isset($arr['destination'], $arr['headers']) && is_string($arr['destination']) && strlen(trim($arr['destination'])) > 5 && count(explode('@', $arr['destination'])) == 2 && is_string($arr['headers']) && strlen(trim($arr['headers'])) > 3) { error_log($msg, 1, trim($arr['destination']), trim($arr['headers'])); } else { if ($arr['type'] == 3 && isset($arr['destination']) && is_string($arr['destination']) && strlen(trim($arr['destination'])) > 1) { error_log($msg, 3, trim($arr['destination'])); } else { if (defined('DISPLAY_XPM4_ERRORS') && DISPLAY_XPM4_ERRORS == true) { trigger_error('invalid LOG_XPM4_ERRORS constant value', E_USER_WARNING); } } } } } else { if (defined('DISPLAY_XPM4_ERRORS') && DISPLAY_XPM4_ERRORS == true) { trigger_error('invalid LOG_XPM4_ERRORS constant type', E_USER_WARNING); } } } else { if (defined('DISPLAY_XPM4_ERRORS') && DISPLAY_XPM4_ERRORS == true) { trigger_error('invalid parameter(s) type', E_USER_WARNING); } } } }
protected function closed($user) { error_log("[echoServer.closed] closed .." . $user->id); // Do nothing: This is where cleanup would go, in case the user had any sort of // open files or other objects associated with them. This runs after the socket // has been closed, so there is no need to clean up the socket itself here. }
static function cachableDataset($n) { $flg_exit = false; /* if(isset($_SESSION['cache_' . $n ])){ $gmdate_mod = $_SESSION['cache_' . $n ]; $flg_exit = true; }else{ $gmdate_mod = gmdate('D, d M Y H:i:s') . ' GMT'; $_SESSION['cache_' . $n ] = $gmdate_mod; } */ $gmdate_mod = gmdate('D, d M Y H:i:s') . ' GMT'; header("HTTP/1.1 304 Not Modified"); header("Date: {$gmdate_mod}"); header("Last-Modified: {$gmdate_mod}"); header("Cache-Control: public, max-age=86400, must-revalidate"); header("Pragma: cache"); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 86400) . ' GMT'); error_log("============ Called cachableDataset {$n} {$gmdate_mod} =========================================="); if ($flg_exit) { exit; } error_log("============ Creating cachableDataset {$n} {$gmdate_mod} =========================================="); $a = new rea_ui_dataset(); return $a; }
public static function debug($str, $level = false) { if (self::$debug) { error_log($str); } //Z_Log::log(Z_CONFIG::$LOG_TARGET_DEFAULT, $str); }
public function validate() {/*{{{*/ $msg = ''; foreach ($this->dbreads as $dbread){ $link = mysql_connect($dbread['host'], $this->account['user'], $this->account['pass']); $res = mysql_query('show slave status', $link); $row = mysql_fetch_assoc($res); if (empty($row)) { $msg .= $dbread['host'].' can\'t be connected;'; } else if ($this->max < $row['Seconds_Behind_Master']) { error_log("\n".date('Y-m-d H:i:s').":\n".print_r($row, true), 3, '/tmp/db.log'); $msg .= $dbread['host'].' delay '.$row['Seconds_Behind_Master'].';'; } else if ('' != $row['Last_Error']) { $msg .= $dbread['host'].' has error!'; } else if ('Yes' != $row['Slave_IO_Running'] || 'Yes' != $row['Slave_SQL_Running']) { $msg .= $dbread['host'].' has repl error!'; } else if ('' != $row['Last_IO_Error']) { $msg .= $dbread['host'].' has io error!'; } else if ('' != $row['Last_SQL_Error']) { $msg .= $dbread['host'].' has sql error!'; } mysql_close($link); } return $msg; }/*}}}*/
/** * Print a warning, as a call to this function means that $SIMPLESAML_INCPREFIX is referenced. * * @return A blank string. */ function __toString() { $backtrace = debug_backtrace(); $where = $backtrace[0]['file'] . ':' . $backtrace[0]['line']; error_log('Deprecated $SIMPLESAML_INCPREFIX still in use at ' . $where . '. The simpleSAMLphp library now uses an autoloader.'); return ''; }
function log($msg, $subject = null) { if ($this->_debugLogDestination) { if ($this->_debugLogDestination == 'stdout') { if ($this->_debugHtml) { print_r("<pre>"); if ($subject) { print_r("{$subject} :<br/>"); } print_r(htmlentities($msg) . "\r\n"); print_r("</pre>"); } else { if ($subject) { print_r($subject . ' : ' . "\r\n"); } print_r($msg . "\r\n"); } } else { ob_start(); echo date('r') . "\t" . $subject . "\t"; print_r($msg); echo "\r\n"; error_log(ob_get_clean(), 3, $this->_debugLogDestination); } } }
/** * susbscribe valid, unique $request['email'] to * boston meshnet mailing list -- thank you finn! **/ public function subscribe($email) { $base_uri = 'https://lists.projectmesh.net/cgi-bin/mailman/subscribe/boston'; $client = new \Guzzle\Service\Client(['base_uri' => 'https://lists.projectmesh.net/cgi-bin/mailman/subscribe/boston', 'timeout' => 7]); $randStrng = str_random(12); error_log(json_encode(['$randStrng' => $randStrng])); $request = $client->post($base_uri, ['content-type' => 'application/x-www-form-urlencoded'], []); $data = ['email' => $email, 'pw' => $randStrng, 'pw-conf' => $randStrng, 'digest' => 0, 'email-button' => 'Subscribe']; $request->setBody($data); $response = $request->send(); /* Pending mailserver install.. $data = (object) [ 'lists' => '*****@*****.**', 'lists_public' => '*****@*****.**', 'from' => $email, 'subject' => 'Mailing List Request from Boston Meshnet (via Bostonmesh.net Website)', 'artisan' => '*****@*****.**', ] ; $success = Mail::send('emails.subscribe', [ 'data' => $data ], function ($message) use($data) { $message->from($data->from); $message->to($data->lists) ->cc($data->artisan) ->cc($data->from) ->subject($data->subject); }); error_log(json_encode(['subscribe' => $success])); */ $success = true; return ['success' => $success]; }
function debuglog($mit) { global $release; if ($release == "dev") { error_log(date("[G:i:s] ") . $mit, 3, "/tmp/php3-ibusz.log"); } }
public function updateQuestion($question_id, $array) { $this->db->where('question_id', $question_id); if (isset($array['question_name'])) { $this->db->set('question_name', $array['question_name']); } if (isset($array['question_url_name'])) { $this->db->set('question_url_name', $array['question_url_name']); } if (isset($array['question_desc'])) { $this->db->set('question_desc', $array['question_desc']); } if (isset($array['question_status'])) { $this->db->set('question_status', $array['question_status']); } if (isset($array['question_answer'])) { $this->db->set('question_answer', $array['question_answer']); } if (isset($array['flag_reason'])) { $this->db->set('flag_reason', $array['flag_reason']); } if (isset($array['flag_reason_other'])) { $this->db->set('flag_reason_other', $array['flag_reason_other']); } $this->db->update('cn_questions'); error_log(trim($this->db->last_query())); log_message('debug', "updateQuestion:" . trim($this->db->last_query())); return $this->db->affected_rows(); }
function &create(&$root, &$pipeline) { $name = $root->get_attribute('name'); $value = $root->get_attribute('value'); $url_autofix = new AutofixUrl(); $src = $url_autofix->apply(trim($root->get_attribute("src"))); $src_img = ImageFactory::get($pipeline->guess_url($src), $pipeline); if (is_null($src_img)) { error_log(sprintf("Cannot open image at '%s'", $src)); if ($root->has_attribute('width')) { $width = px2pt($root->get_attribute('width')); } else { $width = px2pt(BROKEN_IMAGE_DEFAULT_SIZE_PX); } if ($root->has_attribute('height')) { $height = px2pt($root->get_attribute('height')); } else { $height = px2pt(BROKEN_IMAGE_DEFAULT_SIZE_PX); } $alt = $root->get_attribute('alt'); $css_state =& $pipeline->get_current_css_state(); $box =& new ButtonBrokenImagebox($width, $height, $alt, $name, $value, $css_state->get_property(CSS_HTML2PS_FORM_ACTION)); $box->readCSS($css_state); return $box; } $css_state =& $pipeline->get_current_css_state(); $box =& new ButtonImageBox($src_img, $name, $value, $css_state->get_property(CSS_HTML2PS_FORM_ACTION)); $box->readCSS($css_state); $box->_setupSize(); return $box; }
/** * 自定义错误处理 * * @param $errorNo * @param $errorStr * @param $errorFile * @param $errorLine * * @return bool */ function custom_error_handler($errorNo, $errorStr, $errorFile, $errorLine) { $logFile = "PHP_log_%s_" . date('Ynd') . '.log'; $now = date('Y-m-d H:i:s'); $templateStr = "[{$now}] %s on line {$errorLine} in file {$errorFile} : {$errorStr}" . PHP_EOL; $logStr = ''; switch ($errorNo) { case E_USER_ERROR: $logFile = sprintf($logFile, 'ERROR'); $logStr = sprintf($templateStr, 'Fatal error'); break; case E_USER_WARNING: $logFile = sprintf($logFile, 'WARNING'); $logStr = sprintf($templateStr, 'WARNING'); break; case E_USER_NOTICE: $logFile = sprintf($logFile, 'NOTICE'); $logStr = sprintf($templateStr, 'NOTICE'); break; } if ($logStr != '') { error_log($logStr, 3, $logFile); } return true; }
protected function attempt_upload() { // If there was an attempt to upload a file if (isset($_FILES[$this->fileindex]) && (!isset($_FILES[$this->fileindex]['error']) || $_FILES[$this->fileindex]['error'] != 4)) { // error 4 = no file chosen anyway if (isset($_FILES[$this->fileindex]['error']) && $_FILES[$this->fileindex]['error'] != 0) { error_log('JSON Key file upload error number ' . $_FILES[$this->fileindex]['error']); // Some import errors have error explanations $this->error = 'file_upload_error' . (in_array($_FILES[$this->fileindex]['error'], array(2, 6, 7)) ? $_FILES[$this->fileindex]['error'] : ''); return; } if (isset($_FILES[$this->fileindex]['size']) && $_FILES[$this->fileindex]['size'] <= 0) { $this->error = 'no_content'; return; } $filepath = $_FILES[$this->fileindex]['tmp_name']; $this->contents = @file_get_contents($filepath); } else { if (strlen(trim($this->jsontext)) > 0) { $this->contents = strpos($this->jsontext, '\\\\') !== false ? stripslashes($this->jsontext) : $this->jsontext; } } if ($this->contents !== null) { $this->read_json(); } }
/** * Performs the actual image manipulation, * including saving the target file. * * @param string $load_filename filepath (not URL) to source file * (ex: /src/var/www/wp-content/uploads/my-pic.jpg) * @param string $save_filename filepath (not URL) where result file should be saved * (ex: /src/var/www/wp-content/uploads/my-pic@2x.jpg) * @return bool true if everything went fine, false otherwise */ function run($load_filename, $save_filename) { $image = wp_get_image_editor($load_filename); if (!is_wp_error($image)) { $current_size = $image->get_size(); $src_w = $current_size['width']; $src_h = $current_size['height']; // Get ratios $w = $src_w * $this->factor; $h = $src_h * $this->factor; $image->crop(0, 0, $src_w, $src_h, $w, $h); $result = $image->save($save_filename); if (is_wp_error($result)) { error_log('Error resizing image'); error_log(print_r($result, true)); return false; } else { return true; } } else { if (isset($image->error_data['error_loading_image'])) { TimberHelper::error_log('Error loading ' . $image->error_data['error_loading_image']); } else { TimberHelper::error_log($image); } } return false; }
/** * Get the words from each language * @return array */ public function getLangaugeWord() { $langPath = $this->_config->getLanguageFolder(); $root = PathService::getRootDir(); $absLangPath = $root . DIRECTORY_SEPARATOR . $langPath; $ignore = array('.', '..', '.svn', '.DS_Store'); $langArray = array(); if ($handle = opendir($absLangPath)) { while (false !== ($file = readdir($handle))) { $absFile = $absLangPath . DIRECTORY_SEPARATOR . $file; $tLangArr = array(); if (!in_array($file, $ignore) && !is_dir($absFile)) { try { if (($tLangArr = @parse_ini_file($absFile, true)) == false) { throw new Exception('Cannot Parse INI file: ' . $absFile); } } catch (Exception $e) { error_log($e->getMessage()); } $langArray = array_merge($langArray, $tLangArr); } } } return $langArray; }
function updateChangedPages() { $task = new BackgroundProcess_UpdateChangedPages(); $task->changedTranslationMemories = $this->changedTranslationMemories; $task->save(); error_log('Added task UpdateChangedPages'); }
public function err($msg, $file = null) { if (!empty($this->_emailFrom) && !empty($this->_emailTo) && !empty($this->_emailSubject) && $msg instanceof Exception) { if (!$msg instanceof Wk_Exception) { $body = print_r($msg, true); $subject = "=?UTF-8?B?" . base64_encode($this->_emailSubject) . "?="; $header = "MIME-Version: 1.0" . "\r\n"; $header .= "Content-type:text/html;charset=utf-8" . "\r\n"; $header .= 'From: <' . $this->_emailFrom . '>' . "\r\n"; mail($this->_emailTo, $subject, $body, $header); } $msg = $msg->getMessage() . $msg->getTraceAsString(); } if ($msg instanceof Exception) { $msg = $msg->getMessage() . $msg->getTraceAsString(); } if (empty($file) && empty($this->_errPath)) { return; } if (empty($file)) { $file = $this->_errPath; } if ($this->_rotate) { $file .= '.' . date('Ymd'); } error_log(self::formatLogMessage($msg, 'error', true), 3, $file); }
public function send() { $di = \Phalcon\DI::getDefault(); $res = $di->get('response'); $req = $di->get('request'); //query string, filter, default if (!$req->get('suppress_response_codes', null, null)) { $res->setStatusCode($this->getCode(), $this->response)->sendHeaders(); } else { $res->setStatusCode('200', 'OK')->sendHeaders(); } $error = array('errorCode' => $this->getCode(), 'messages' => $this->messages); if (!$req->get('type') || $req->get('type') == 'json') { $response = new \Base\Framework\Responses\JSONResponse(); $response->send($error, true); return; } else { if ($req->get('type') == 'csv') { $response = new \Base\Framework\Responses\CSVResponse(); $response->send(array($error)); return; } } error_log('HTTPException: ' . $this->getFile() . ' at ' . $this->getLine()); return true; }
protected function execute($report, $query, $parameters) { $report->DB()->SetFetchMode(ADODB_FETCH_ASSOC); $rs = $report->DB()->Execute($query, $parameters); if (!$rs) { error_log($report->DB()->ErrorMsg()); return array("ERROR", "Error generating report"); } $reportNamesFilled = false; $columnNames = array(); $reportData = array(); foreach ($rs as $rowId => $row) { $reportData[] = array(); if (!$reportNamesFilled) { $countIt = 0; foreach ($row as $name => $value) { $countIt++; $columnNames[$countIt] = $name; $reportData[count($reportData) - 1][] = $value; } $reportNamesFilled = true; } else { foreach ($row as $name => $value) { $reportData[count($reportData) - 1][] = $value; } } } array_unshift($reportData, $columnNames); return $reportData; }
function PQuery($query) { require "config.php"; global $connection; //error_log( $query ); //print $query."<br>"; $res = pg_query($connection, $query); if (!$res) { //print_r (debug_backtrace()); list(, $caller) = debug_backtrace(false); error_log($caller['function'] . ', ' . $caller['line'] . ": {$query}"); $result['count'] = 0; $result['rows'] = NULL; $result['error'] = pg_last_error($connection); return $result; } $result['count'] = pg_num_rows($res); $i = 0; $rowarr = array(); while ($row = pg_fetch_array($res, NULL, PGSQL_ASSOC)) { $rowarr[$i++] = $row; } pg_free_result($res); $result['rows'] = $rowarr; return $result; }