Nette\Database\Context::fetchField PHP Method

fetchField() public method

Shortcut for query()->fetchField()
public fetchField ( $sql, $params ) : mixed
return mixed
    public function fetchField($sql, ...$params)
    {
        return $this->connection->query($sql, ...$params)->fetchField();
    }

Usage Example

Example #1
0
 public function loadLob()
 {
     $stop = $this->database->fetchField("select max(unix_timestamp(published))>(unix_timestamp(now())-100) from lob_items;");
     if ($stop) {
         return;
     }
     $channels = $this->getLobChannels();
     foreach ($channels as $channel) {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $channel['link']);
         $redirects = 0;
         $page = $this->curl_redirect_exec($ch, $redirects, true);
         curl_close($ch);
         if (empty($page)) {
             continue;
         }
         $html = HtmlDomParser::str_get_html($page);
         foreach ($html->find('#page-body .post') as $element) {
             if (isset($element->id)) {
                 $id = preg_replace("/[^0-9,.]/", "", $element->id);
             } else {
                 continue;
             }
             $lobItem = $this->getLobItemByPostId($id);
             if (!empty($lobItem)) {
                 continue;
             }
             $arr = array();
             $content = $element->find('.content', 0);
             $author = $element->find('.postprofile dt', 0);
             $datestring = $element->find('.author', 0);
             $arr['content'] = trim($content->innertext);
             $arr['author'] = trim($author->plaintext);
             $arr['datestring'] = trim(preg_replace("/.*»/", "", $datestring->innertext));
             $arr['post_id'] = $id;
             $this->database->query('insert into lob_items ', $arr);
         }
     }
 }
All Usage Examples Of Nette\Database\Context::fetchField