Example #1
0
 /**
  * takes any terms used in a search and inserts them into a sql database
  *
  * @param $search_term
  */
 function trackSearchTerm($search_term)
 {
     $search_term = stripslashes($search_term);
     $sql = "INSERT DELAYED INTO search_statistics (search_term, wp_id, date_stamp) VALUES(?, ?, NOW())";
     PSU::db('go')->Execute($sql, array($search_term, $this->wp_id));
     $this->trackKeywordUsage(459, 359);
     StatsD\StatsD::increment('app.go.search');
 }
 /**
  * Connect to a database, or return connection parameters.
  *
  * @since     version 1.0.0
  * @param     string $connect_data Connection identifier(s).
  * @param     string $return Return type. One of: adodb (ADOdb object), mysql (raw mysql_connect() resource), return (connection parameters as an array).
  * @return    mixed See the $return parameter.
  */
 public function connect($connect_data, $return = 'adodb', $memcache = true)
 {
     //if the connect_data is not an array, lets make it one so life is easier
     if (!is_array($connect_data)) {
         $connect_data = array($connect_data);
     }
     //end if
     $dbs = array();
     //loop over connection array and connect to the databases!
     foreach ($connect_data as $key => $connect) {
         $connect = explode('/', $connect);
         //include the db connection info
         include $connect[0] . '/' . $connect[1] . '.php';
         StatsD\StatsD::increment("db.attempt.{$connect[0]}.{$connect[1]}");
         $options = array_slice($connect, 2);
         //decide which object to create
         switch ($return) {
             case 'adodb':
                 require_once 'adodb5/adodb.inc.php';
                 switch ($connect[0]) {
                     case 'oracle':
                         $driver = in_array('fixcase', $options) ? 'oci8po' : 'oci8';
                         break;
                     case 'mssql':
                         $driver = 'mssqlpo';
                         break;
                         // disabled by defautl because ADO_RecordSet::RecordCount() does not work on
                         // PDO connections. PDO supports rowCount(), but ADOdb will not use it unless
                         // $ADODB_COUNTRECS is true. -- ambackstrom, 4 sept 2009
                     // disabled by defautl because ADO_RecordSet::RecordCount() does not work on
                     // PDO connections. PDO supports rowCount(), but ADOdb will not use it unless
                     // $ADODB_COUNTRECS is true. -- ambackstrom, 4 sept 2009
                     case 'mysql':
                         $driver = 'mysql';
                         break;
                         // DEBUG: disabling pdo support for now, it's not enabled on perseus
                         if (!in_array('pdo', $options)) {
                             $driver = 'mysql';
                             break;
                         }
                         $driver = 'pdo';
                         $port = null;
                         $host = $_DB[$connect[0]][$connect[1]]['hostname'];
                         if (strpos($host, ':') !== false) {
                             list($host, $port) = explode(':', $host);
                         }
                         $_DB[$connect[0]][$connect[1]]['hostname'] = 'mysql:host=' . $host . ($port ? ';port=' . $port : '');
                         unset($host, $port);
                         break;
                     default:
                         $driver = $connect[0];
                         break;
                 }
                 //end switch
                 global $ADODB_COUNTRECS;
                 global $ADODB_CACHE_DIR;
                 global $ADODB_FORCE_TYPE;
                 global $ADODB_GETONE_EOF;
                 global $ADODB_QUOTE_FIELDNAMES;
                 $user = posix_getpwuid(posix_geteuid());
                 $ADODB_COUNTRECS = false;
                 $ADODB_CACHE_DIR = '/web/temp/ADOdbCache_' . md5($user['name']);
                 $ADODB_GETONE_EOF = false;
                 $ADODB_QUOTE_FIELDNAMES = true;
                 $ADODB_FORCE_TYPE = ADODB_FORCE_IGNORE;
                 if (!file_exists($ADODB_CACHE_DIR)) {
                     mkdir($ADODB_CACHE_DIR, 0700);
                 }
                 //end if
                 if (!ADODB_PREFETCH_ROWS) {
                     define('ADODB_PREFETCH_ROWS', 50);
                 }
                 $db = ADONewConnection($driver);
                 if (substr($driver, 0, 4) == 'oci8') {
                     $db->_initdate = false;
                     // persistent oracle connections
                     $db->autoRollback = true;
                     // must rollback; don't use existing transaction
                     $connect_method = 'PConnect';
                 } else {
                     $connect_method = 'NConnect';
                 }
                 if (in_array('debug', $options)) {
                     $db->debug = true;
                 }
                 if (in_array('nocache', $options)) {
                     $db->cacheSecs = 0;
                 } else {
                     $db->cacheSecs = 600;
                 }
                 $db->SetFetchMode(ADODB_FETCH_ASSOC);
                 if ($memcache) {
                     $db->memCache = true;
                     $db->memCacheHost = 'sualocin.plymouth.edu';
                     // $db->memCacheHost = $ip1; will work too
                     $db->memCachePort = PSU::isdev() ? 21217 : 11217;
                     // this is default memCache port
                     $db->memCacheCompress = MEMCACHE_COMPRESSED;
                     // Use 'true' to store the item compressed (uses zlib)
                 }
                 // modify some fields so date inserts get hour/minute/second as
                 // well as the date. affects SYSDATE
                 $db->dateformat = $db->NLS_DATE_FORMAT = 'RRRR-MM-DD HH24:MI:SS';
                 $db->fmtDate = "'Y-m-d H:i:s'";
                 $db->fmtTimeStamp = "'Y-m-d H:i:s'";
                 //$db->sysDate = 'TRUNC(SYSDATE)'; // function that returns today's date. this is adodb-oci8's default
                 $connected = $db->{$connect_method}($_DB[$connect[0]][$connect[1]]['hostname'], $_DB[$connect[0]][$connect[1]]['username'], PSUSecurity::password_decode($_DB[$connect[0]][$connect[1]]['password']), $_DB[$connect[0]][$connect[1]]['database']);
                 // need the default PDO MySQL behavior to be non-fixcase, for legacy code
                 if ($connected && $driver === 'pdo' && $connect[0] === 'mysql') {
                     if (in_array('fixcase', $options)) {
                         $db->_connectionID->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
                     } else {
                         $db->_connectionID->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
                     }
                 }
                 if (!$connected) {
                     StatsD\StatsD::increment("db.failure.{$connect[0]}.{$connect[1]}");
                 }
                 if ($connect[0] == 'oracle') {
                     $sql = "ALTER SESSION SET nls_date_format = 'YYYY-MM-DD HH24:MI:SS'";
                     $db->Execute($sql);
                 }
                 break;
             case 'mysql':
                 $db = mysql_connect($_DB[$connect[0]][$connect[1]]['hostname'], $_DB[$connect[0]][$connect[1]]['username'], PSUSecurity::password_decode($_DB[$connect[0]][$connect[1]]['password']));
                 mysql_select_db($_DB[$connect[0]][$connect[1]]['database'], $db);
                 break;
             case 'return':
                 $db = $_DB[$connect[0]][$connect[1]];
                 break;
         }
         //end switch
         //unset the password so it doesn't appear in debug
         unset($db->password);
         $dbs[$key] = $db;
     }
     //end foreach
     return count($dbs) == 1 ? $dbs[0] : $dbs;
 }
 /**
  * stopTimer
  *
  * stop the timer on the cron
  *
  * @access	public
  * @return	mixed current runtime when stopped
  */
 function stopTimer()
 {
     $this->_end_time = time();
     $this->_run_time = $this->_end_time - $this->_start_time;
     StatsD\StatsD::timing('cron.web.' . $this->_app_name, microtime(true) - $this->_start_time);
     return $this->_run_time;
 }