Example #1
0
 /**
  * Fetch results from PDO statement object
  * @param  object $statement  Prepared PDO statement object
  * @param  string $fetchStyle Style of returned row(s)
  * @return mixed              Returned row(s)
  */
 public function fetch($statement, $fetchStyle)
 {
     if ($fetchStyle === PDO::FETCH_CLASS) {
         return $statement->fetchAll(PDO::FETCH_CLASS, 'stdClass');
     } else {
         return $statement->fetchAll($fetchStyle);
     }
 }
Example #2
0
 /**
  * Fetches the results of the executed statement
  * @static
  * @param string $sql A string of the sql query
  * @param array $params An array of the parameter
  * @param int $method The code for the fetch Method to be used, defaulst to FETCH_ASSOC
  * @return array Returns an array of rows from the database
  * @since version 2.0
  */
 public static function fetchAll($sql, $params = array(), $method = PDO::FETCH_ASSOC)
 {
     try {
         return self::execute($sql, $params) ? self::$stmt->fetchAll($method) : false;
     } catch (PDOException $e) {
         return self::pdoException($e);
     }
 }
Example #3
0
File: Pdo.php Project: mwyatt/core
 public function fetchAll($mode = \PDO::FETCH_ASSOC, $argument = null)
 {
     if ($argument) {
         return $this->statement->fetchAll($mode, $argument);
     } else {
         return $this->statement->fetchAll($mode);
     }
 }
 /**
  * Call this method from the appropriate action method
  *
  * @return ApiProblemResponse|JsonModel
  */
 public function handleRequest()
 {
     $request = $this->getRequest();
     if ($request->getMethod() != $request::METHOD_GET) {
         return new ApiProblemResponse(new ApiProblem(405, 'Only the GET method is allowed for this URI'));
     }
     $model = new JsonModel([$this->property => $this->model->fetchAll()]);
     $model->setTerminal(true);
     return $model;
 }
Example #5
0
 /**
  * method for fetching rows which we created with our query
  * @return array $rows assoc array of rows
  */
 public static function fetch()
 {
     try {
         self::$debug[] = self::$query;
         self::init();
         self::$stmt = self::$dbh->prepare(self::$query);
         self::prepare();
         self::$stmt->execute();
         $rows = self::$stmt->fetchAll(PDO::FETCH_ASSOC);
         if (self::$method == 'select_one') {
             if (!empty($rows)) {
                 $rows = $rows[0];
             }
         }
         self::unsetVars();
     } catch (Exception $e) {
         $message = $e->getTraceAsString();
         log::error($message);
         $last = self::getLastDebug();
         log::error($last);
         die;
     }
     if (self::$method == 'num_rows') {
         return $rows[0]['num_rows'];
     }
     return $rows;
 }
Example #6
0
 /**
  * helper to retrieve sigle column from result
  *
  * @param	string 	the column to be retrieved
  * @return	array	result
  */
 protected function getCol($colName = '')
 {
     $all = $this->statement->fetchAll();
     if (empty($colName)) {
         $colName = key($all[0]);
     }
     return array_column($all, $colName);
 }
Example #7
0
 /**
  * Check for a twitter id in the database
  * @access private
  * @param integer $tid a twitter id(required)
  * @return boolean 
  */	
 private function checkTID($tid) {
     $this->db->setFetchMode(Zend_Db::FETCH_OBJ);
     
     $result = $this->db->fetchAll('SELECT * FROM '.$this->table_name.' WHERE tid = ?', $tid);
     
     return $result;
     
 }
Example #8
0
 /**
  * Get count of all ids in the database - since they're unique this is the total tweets for that hash tag
  * @access public
  * @return object 
  */	
 public function getTagCount() {
     $this->db->setFetchMode(Zend_Db::FETCH_ASSOC);
     
     $result = $this->db->fetchAll('SELECT COUNT(*) as "tweet_count" FROM '.$this->table_name);
     
     return $result[0];
     
 }
Example #9
0
 /**
  * Check existing of hash
  *
  * @static
  * @param string $hash
  * @param object $db
  * @param string $table
  * @return bool
  */
 protected static function _isNotExist($hash, $db, $table)
 {
     $select = $db->select()->from($table)->where('hash=?', $hash);
     $records = $db->fetchAll($select);
     if (empty($records)) {
         return true;
     }
     return false;
 }
Example #10
0
 public function renderDefault()
 {
     $this->pager->itemCount = $this->gallery->getCount();
     $this->pager->itemsPerPage = $this->onPage;
     $this->page = $this->pager->getPage();
     $this->template->list = $this->gallery->fetchAll($this->page, $this->onPage, $this->orderBy, $this->sort);
     $this->template->sort = $this->sort;
     $this->template->orderBy = $this->orderBy;
     $this->template->title = $this->documentName;
     if (isset($this->mainSession->filter)) {
         $this['filterForm']->setDefaults($this->mainSession->filter);
     }
     $this->template->showFilter = null;
     //$this->mainSession->filterName;
     $this->template->showSavedFilters = $this->gallery->getSavedFilters();
     $trash = $this->gallery->getTrash();
     $this->template->trashCount = $trash['count'];
     $this->template->trash = $trash['items'];
 }
 /**
         This method executes the prepared query
         @access public
  		@throws PDOException object
         @return array or object
 */
 public function result_set()
 {
     try {
         self::execute();
         $result = $this->Stmt->fetchAll(PDO::FETCH_OBJ);
         self::close_cursor();
         return $result;
     } catch (PDOException $e) {
         throw $e;
     }
 }
Example #12
0
    /**
     * Get latest tweet from database and output the json
     * @access public
     * @return object 
     */	
    public function getLatestTweet() {
        $this->db->setFetchMode(Zend_Db::FETCH_ASSOC);
        
        $result = $this->db->fetchAll('SELECT profile_img, name, username, text FROM '.$this->table_name.' ORDER BY id DESC LIMIT 1');
        
//        echo '<pre>';
//        print_r($result);
        
        return $result;
        
    }
Example #13
0
 /**
  * 获得所有的查询数据
  * @param string $sql  要执行的SQL指令
  * @param boolean $primkey 是否以主键为下标。使用主键下标,可以返回以数据库主键的值为下标的二维数组
  * @return array 查询得到的数据集,失败返回false
  * @access public
  */
 public function getAll($sql, $primkey = false)
 {
     $this->query($sql);
     if ($primkey) {
         $result = $this->PDOStatement->fetchAll(PDO::FETCH_GROUP | PDO::FETCH_ASSOC);
         $result = array_map('reset', $result);
     } else {
         $result = $this->PDOStatement->fetchAll(PDO::FETCH_ASSOC);
     }
     $this->PDOStatement = null;
     return $result;
 }
Example #14
0
 /**
  * determineAutoIncrement()
  * Determines Autoincrement Field if not set
  * @access private
  * @return void
  */
 private function determineAutoIncrement()
 {
     if (!$this->orderByField) {
         $query = "DESCRIBE " . $this->table;
         $result = $this->db->fetchAll($query);
         foreach ($result as $row) {
             if ($row['Extra'] == 'auto_increment') {
                 $this->orderByField = $row['Field'];
             }
         }
     }
 }
Example #15
0
 /**
  * Return Table Fields of Requested Table
  * 
  * @param string $sTable
  * @return array Field Type and Field Name
  */
 public function getFields($sTable = '')
 {
     $sSql = "DESC {$sTable};";
     $this->_oSTH = $this->prepare($sSql);
     $this->_oSTH->execute();
     $aColList = $this->_oSTH->fetchAll();
     foreach ($aColList as $key) {
         $aField[] = $key['Field'];
         $aType[] = $key['Type'];
     }
     return array_combine($aField, $aType);
 }
Example #16
0
 /**
  * Find the most concacted members between the supplied user
  * @since Version 3.10.0
  * @return array
  */
 public function getMostContactedUsers()
 {
     if (!$this->Author instanceof User) {
         throw new Exception(__NAMESPACE__ . "::Author has not been set");
     }
     $query = "SELECT COUNT(*) AS num_msgs, pm.privmsgs_to_userid AS user_id, u.username, u.user_avatar\n                        FROM nuke_bbprivmsgs AS pm \n                            LEFT JOIN nuke_users AS u ON u.user_id = pm.privmsgs_to_userid \n                        WHERE pm.privmsgs_from_userid = ? \n                        AND pm.privmsgs_to_userid != ? \n                        AND pm.privmsgs_date >= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 90 day)) \n                        GROUP BY pm.privmsgs_to_userid \n                        ORDER BY COUNT(*) DESC \n                        LIMIT 0, 10";
     $params = [$this->Author->id, $this->Author->id];
     $users = $this->db->fetchAll($query, $params);
     foreach ($users as $key => $row) {
         $users[$key]['url'] = UserUrlUtility::MakeURLs($row)->getURLs();
         $users[$key]['avatar'] = array("tiny" => AvatarUtility::Format($row['user_avatar'], 25, 25), "thumb" => AvatarUtility::Format($row['user_avatar'], 50, 50), "small" => AvatarUtility::Format($row['user_avatar'], 75, 75), "medium" => AvatarUtility::Format($row['user_avatar'], 100, 100));
     }
     return $users;
 }
Example #17
0
 /**
  * Server getTestDetails
  * Function used to fetch mls testdetails
  * @author Naheeda<*****@*****.**>
  * @param type $details
  * @return type
  */
 public function getTestDetails()
 {
     $selectFields = 't.application_uid, t.tbl_mls_id, t.tested_date, t.status, m.name AS mls_shortname, m.submitted_date,m.mls_name,
                      u.name AS tester_name, u.role';
     $sql = "SELECT {$selectFields}\n                 FROM tbl_compliants_tests t\n                 INNER JOIN tbl_mls m \n                 ON m.name = t.tbl_mls_id\n                 INNER JOIN  `tbl_users` u \n                 ON u.id = t.tester_id\n                 ORDER BY m.name";
     $result = array();
     $result = $this->_db->fetchAll($sql);
     $array_length = sizeof($result);
     for ($i = 0; $i < $array_length; $i++) {
         $result[$i]['tester_name'] = ucfirst($result[$i]['tester_name']);
         $result[$i]['status'] = ucfirst($result[$i]['status']);
         $result[$i]['mls_shortname'] = strtoupper($result[$i]['mls_shortname']);
     }
     return $result;
 }
 /**
  * 获取全部查询信息
  *
  * @access public
  *
  * @param string $model 返回数据的索引类型:字段型/数据型 等。默认:字段型
  *
  * @return array
  */
 public function fetchAll($model = PDO::FETCH_ASSOC)
 {
     //参数分析
     if (!$model) {
         return false;
     }
     if (!$this->_query) {
         return false;
     }
     $myrow = $this->_query->fetchAll($model);
     $this->_query->closeCursor();
     //重值$this->_query
     $this->_query = null;
     return $myrow;
 }
Example #19
0
File: Orm.php Project: pancke/yyaf
 /**
  * 获取数据库数据
  *
  * @param string $sSQL
  * @param array $aParam
  * @param int $iType
  *            1-column, 2-row, 3-list
  * @return array/string
  */
 protected function _getDBData($sSQL, $aParam, $iType, $bStrictMaster)
 {
     $this->_exectue($sSQL, $aParam, $bStrictMaster, false);
     $this->_oSth->setFetchMode(PDO::FETCH_ASSOC);
     switch ($iType) {
         case 1:
             $mData = $this->_oSth->fetchColumn();
             break;
         case 2:
             $mData = $this->_oSth->fetch();
             break;
         case 3:
             $mData = $this->_oSth->fetchAll();
             break;
     }
     return $mData;
 }
Example #20
0
 /**
  * Runs a query and limits results based on predefined data
  *
  * @param string $sql
  * @return array
  */
 function selectAllPaged($sql)
 {
     //set the current page
     $data = $this->_request->getParams();
     if ($data['page'] && $data['page'] > 1) {
         $this->curPage = (int) $data['page'] - 1;
     } else {
         $this->curPage = 0;
     }
     $this->toTpl('curpage', $this->curPage);
     $from = $this->curPage * 20;
     $p = $this->db->fetchAll($sql);
     $this->pager = $this->paginate(count($p));
     $this->toTpl('pager', $this->pager);
     $c = $this->db->fetchAll($sql . " LIMIT {$from},20");
     return $c;
 }
 /**
  * Fetches all rows from the PDOStatement object into the resultset.
  *
  * @param string $DatasetType The format in which the result should be returned: object or array.
  * It will fill a different array depending on which type is specified.
  */
 protected function _FetchAllRows($DatasetType = FALSE)
 {
     if (!is_null($this->_Result)) {
         return;
     }
     if ($DatasetType) {
         $this->_DatasetType = $DatasetType;
     }
     $Result = array();
     if (is_null($this->_PDOStatement)) {
         $this->_Result = $Result;
         return;
     }
     $Result = $this->_PDOStatement->fetchAll($this->_DatasetType == DATASET_TYPE_ARRAY ? PDO::FETCH_ASSOC : PDO::FETCH_OBJ);
     //		$this->_PDOStatement->setFetchMode($this->_DatasetType == DATASET_TYPE_ARRAY ? PDO::FETCH_ASSOC : PDO::FETCH_OBJ);
     //      while($Row = $this->_PDOStatement->fetch()) {
     //			$Result[] = $Row;
     //		}
     $this->FreePDOStatement(TRUE);
     $this->_Result = $Result;
 }
 /**
  * Get all messages for administrative purposes
  * @since Version 3.8.7
  * @param int $items_per_page
  * @param int $page
  * @return array
  */
 public function getAllMessages($items_per_page = 25, $page = 1)
 {
     if (!filter_var($items_per_page, FILTER_VALIDATE_INT)) {
         throw new Exception("Cannot fetch messages - invalid items_per_page parameter provided");
     }
     if (!filter_var($page, FILTER_VALIDATE_INT)) {
         throw new Exception("Cannot fetch messages - invalid page number parameter provided");
     }
     $page = ($page - 1) * $items_per_page;
     $query = "SELECT SQL_CALC_FOUND_ROWS privmsgs_id AS id, privmsgs_type AS type, privmsgs_date AS date FROM nuke_bbprivmsgs ORDER BY privmsgs_date DESC LIMIT ?, ?";
     $return = array();
     if ($result = $this->db->fetchAll($query, array($page, $items_per_page))) {
         $return['total'] = $this->db_readonly->fetchOne("SELECT FOUND_ROWS() AS total");
         foreach ($result as $row) {
             $Date = new DateTime();
             $Date->setTimestamp($row['date']);
             $row['date'] = $Date;
             $return['messages'][] = $row;
         }
     }
     return $return;
 }
Example #23
0
 /**
  * getResult()
  * Gets Result data
  *
  * @return array
  */
 public function getResult()
 {
     $this->calculateTotal();
     $this->query = new Query();
     if (!isset($this->select)) {
         $this->select = "*";
     }
     $this->query->select($this->select)->from($this->table);
     if (isset($this->where)) {
         $this->query->where($this->where);
     }
     if (!isset($this->orderByField)) {
         $this->determineAutoIncrement();
     }
     if (isset($this->orderByField)) {
         $this->query->order($this->orderByField, $this->defaultOrder);
     }
     $limitFrom = ($this->currentPage - 1) * $this->itemsPerPage;
     if ($limitFrom >= $this->totalCount) {
         $limitFrom = 0;
     }
     $this->query->limit($limitFrom . ", " . $this->itemsPerPage);
     return $this->db->fetchAll($this->query->getQuery());
 }
Example #24
0
 /**
  * Returns an anonymous object with property names that
  * correspond to the column names returned in all of the result set rows.
  *
  */
 public function resultset()
 {
     $this->execute();
     return $this->stmt->fetchAll(PDO::FETCH_OBJ);
 }
Example #25
0
 /**
  * Test dynamic SELECT WHERE IN queries
  * 
  * @param object $db
  * @param array $testSet
  * @return void
  * @access public
  * @since 4/7/08
  */
 public function testDynamicSelectIN($db, array $testSet)
 {
     foreach ($testSet as $ids) {
         $queryString = "SELECT * FROM log_entry WHERE id IN ('" . implode("', '", $ids) . "')";
         $result = $db->fetchAll($queryString);
         // 			printpre($result);
     }
 }
Example #26
0
 /**
  * Fetches all child from the current collection of children
  *
  * @return array
  * @access public
  */
 function fetchAll()
 {
     return $this->calendar->fetchAll();
 }
Example #27
0
/**
 * Run some coreDatabaseTable tests (ORM)
 * 
 * @param object $db
 * @param object $test
 */
function ormTests($db, $test)
{
    // Testing method access to the table peer attributes
    TestOrmPeer::exampleMethod($test);
    // Testing table data access through the peer class:
    echo "<h2>Select</h2>";
    //$db->setFetchMode(coreDatabase::FETCH_NUM);
    $rows = $db->fetchAll(TestOrmPeer::select());
    $db->dumpResultSet($rows);
    echo "<h2>Count</h2>";
    $test->out(TestOrmPeer::count('id > ?', 24), "count('id > 24')");
    echo "<h2>Insert</h2>";
    TestOrmPeer::insert(array('firstname' => 'Superman', 'age' => 28));
    // show new row
    $id = $db->lastInsertId();
    echo '<p> Inserted new row with id: <b>' . $id . '</b>:';
    $rows = $db->fetchRow(TestOrmPeer::select()->where('id = ?', $id));
    $db->dumpResultSet($rows);
    echo "<h2>Update</h2>";
    // delay 1 second to see the UPDATED_ON changes
    sleep(1);
    TestOrmPeer::update(array('firstname' => 'She-Ra', 'age' => 31), 'id = ?', $id);
    // show update results
    echo '<p> Updated row with id: <b>' . $id . '</b> (1 second delayed):';
    $rows = $db->fetchRow(TestOrmPeer::select()->where('id = ?', $id));
    $db->dumpResultSet($rows);
    echo "<h2>Delete</h2>";
    echo '<p> Deleted row with id: <b>' . $id . '</b>.';
    TestOrmPeer::delete('id >= ?', 27);
}
 /**
  * 获取查询信息的全部数据
  *
  * 注:本函数(类方法)需与query()组合使用。
  *
  * @access public
  *
  * @param string $model 返回数据的索引类型:字段型/数据型 等。默认:字段型
  *
  * @return array
  */
 public function fetchAll($model = 'PDO::FETCH_ASSOC')
 {
     return $this->_dbLink->fetchAll($model);
 }
Example #29
0
 /**
  * Returns an array containing all of the result set rows.
  *
  * @param integer $fetchMode Controls how the next row will be returned to the caller.
  *                             This value must be one of the Doctrine_Core::FETCH_* constants,
  *                             defaulting to Doctrine_Core::FETCH_BOTH.
  * @param integer $columnIndex Returns the indicated 0-indexed column when the value of $fetchStyle is
  *                             Doctrine_Core::FETCH_COLUMN. Defaults to 0.
  *
  * @return array
  */
 public function fetchAll($fetchMode = Doctrine_Core::FETCH_BOTH, $columnIndex = null)
 {
     return $this->statement->fetchAll($fetchMode, $columnIndex);
 }
Example #30
0
 /**
  * Fetch all data with json.
  *
  * @return object Fetch JSON for API.
  */
 public function json()
 {
     return json_decode(self::$data->fetchAll(\PDO::FETCH_ASSOC));
 }