Example #1
0
function get($db)
{
    // takes all records from database
    $result = sqlite_query($db, 'SELECT * FROM users');
    $users = array();
    while ($user = sqlite_fetch_array($result)) {
        $users[] = $user;
    }
    // generate json
    $json = array();
    for ($i = 0; $i < count($users); $i++) {
        $rec = "{";
        $rec .= 'id: "' . $users[$i]['id'] . '",';
        $rec .= 'name: "' . $users[$i]['name'] . '",';
        $rec .= 'age: "' . $users[$i]['age'] . '",';
        $rec .= 'group: "' . $users[$i]['group_name'] . '",';
        $rec .= 'city: "' . $users[$i]['city'] . '",';
        $rec .= 'phone: "' . $users[$i]['phone'] . '",';
        $rec .= 'sex: "' . $users[$i]['sex'] . '",';
        $rec .= 'driver_license: "' . $users[$i]['driver_license'] . '"';
        $rec .= "}";
        $json[] = $rec;
    }
    $json = '[' . implode(',', $json) . ']';
    return $json;
}
Example #2
0
function check_if_exists($cc)
{
    $result = safe_query("SELECT id FROM country_data WHERE cc_code_2='{$cc}'");
    $data = sqlite_fetch_array($result, SQLITE_NUM);
    // return the id or NULL if no data is avaliable
    return $data ? $data[0] : NULL;
}
function query($db, $sql)
{
    $arr = array();
    if (IS_SQLITE3) {
        $rs = $db->query($sql);
        $len = $rs->numColumns();
        while ($row = $rs->fetchArray()) {
            $tmpArr = array();
            for ($i = 0; $i < $len; $i++) {
                $tmpArr[$i] = iconv("gb2312", "UTF-8", $row[$i]);
            }
            array_push($arr, $tmpArr);
        }
    } else {
        $rs = sqlite_query($db, $sql, SQLITE_NUM);
        //echo "<font color='red'>".$error."</font>";
        while ($row = sqlite_fetch_array($rs)) {
            $tmp = array();
            for ($i = 0; $i < count($row); $i++) {
                $tmp[$i] = iconv("gb2312", "UTF-8", $row[$i]);
            }
            array_push($arr, $tmp);
        }
    }
    return $arr;
}
Example #4
0
 /**
  * This function advances the reader to the next record.
  *
  * @access public
  * @override
  * @return boolean                          whether another record was fetched
  */
 public function read()
 {
     if ($this->command !== NULL) {
         $this->record = @sqlite_fetch_array($this->command, SQLITE_ASSOC);
     }
     return $this->record !== FALSE;
 }
 /**
  * Iterator function. Returns a rowset if called without parameter,
  * the fields contents if a field is specified or FALSE to indicate
  * no more rows are available.
  *
  * @param   string field default NULL
  * @return  var
  */
 public function next($field = NULL)
 {
     if (!is_resource($this->handle) || FALSE === ($row = sqlite_fetch_array($this->handle, SQLITE_ASSOC))) {
         return FALSE;
     }
     foreach (array_keys($row) as $key) {
         if (NULL === $row[$key] || !isset($this->fields[$key])) {
             continue;
         }
         switch ($row[$key][0]) {
             case "":
                 $row[$key] = Date::fromString(substr($row[$key], 1));
                 break;
             case "":
                 $row[$key] = intval(substr($row[$key], 1));
                 break;
             case "":
                 $row[$key] = floatval(substr($row[$key], 1));
                 break;
         }
     }
     if ($field) {
         return $row[$field];
     } else {
         return $row;
     }
 }
Example #6
0
 function fetch_array($sql = "")
 {
     if ($sql == "") {
         $sql = $this->query_id;
     }
     $this->record_row = @sqlite_fetch_array($sql, SQLITE_ASSOC);
     return $this->record_row;
 }
Example #7
0
function db_fetch_array($res, $type = SQLITE_ASSOC)
{
    $t = array();
    while ($r = sqlite_fetch_array($res, $type)) {
        $t[] = $r;
    }
    return $t;
}
Example #8
0
 public static function read($id)
 {
     $t = time();
     $sql = "SELECT data FROM sess WHERE expire > {$t} AND id = '" . sqlite_escape_string($id) . "'";
     $r = sqlite_query($sql, SESSION_DB_LINK);
     $d = sqlite_fetch_array($r);
     return '' . is_array($d) ? array_shift($d) : false;
 }
Example #9
0
 /**
  * Fetches all the results
  * @return array
  */
 function fetchAll()
 {
     $result = array();
     while ($row = sqlite_fetch_array($this->query)) {
         $result[] = $row;
     }
     return $result;
 }
Example #10
0
 public function fetch()
 {
     $hRow = sqlite_fetch_array($this->oRes);
     if ($this->sClass && $hRow) {
         return Model::get_instance($this->sClass, $hRow);
     }
     return $hRow;
 }
Example #11
0
 function fetchArray($sql)
 {
     $this->error = "";
     if ($this->versi == 3) {
         return $sql->fetchArray();
     } else {
         return sqlite_fetch_array($sql, SQLITE_ASSOC);
     }
 }
Example #12
0
/**
 * Get the result from the database.
 *
 * @param resource $resource
 *
 * @return array
 */
function db_driver_result($resource)
{
    global $_db;
    $results = array();
    while ($data = sqlite_fetch_array($resource, SQLITE_ASSOC)) {
        $results[] = $data;
    }
    return $results;
}
Example #13
0
File: vdict.php Project: n2i/xvnkb
function vdict_get($db, $word)
{
    if ($db instanceof PDO) {
        $res = $db->query('SELECT * FROM dict WHERE word = ' . $db->quote($word));
        return $res->fetch();
    }
    $res = sqlite_query($db, "SELECT * FROM dict WHERE word = '{$word}'");
    return sqlite_fetch_array($res);
}
 function getOneRecord()
 {
     $record = new lmbSqliteRecord();
     $queryId = $this->connection->execute($this->getSQL());
     $values = sqlite_fetch_array($queryId, SQLITE_ASSOC);
     if (is_array($values)) {
         $record->import($values);
         return $record;
     }
 }
Example #15
0
 function next()
 {
     $ret = FALSE;
     if ($this->hasNext()) {
         $this->current = sqlite_fetch_array($this->id, $this->mode);
         $this->row++;
         $ret = $this->current();
     }
     return $ret;
 }
Example #16
0
 public function FetchArray($result)
 {
     if ($this->connection === false) {
         throw new DatabaseEx('Not connected to a database server!');
     } elseif (!is_resource($result)) {
         throw new DatabaseEx('Invalid Resource For fetchArray()');
     }
     $data = @sqlite_fetch_array($result);
     return $data;
 }
Example #17
0
 /**
  * Create output
  */
 function render($format, &$R, $data)
 {
     if ($format != 'xhtml') {
         return false;
     }
     if (is_null($data)) {
         return false;
     }
     $R->info['cache'] = false;
     $sqlite = $this->dthlp->_getDB();
     if (!$sqlite) {
         return false;
     }
     $this->updateSQLwithQuery($data);
     // handles request params
     // run query
     $clist = array_keys($data['cols']);
     $res = $sqlite->query($data['sql']);
     $cnt = 0;
     $rows = array();
     while ($row = sqlite_fetch_array($res, SQLITE_NUM)) {
         $rows[] = $row;
         $cnt++;
         if ($data['limit'] && $cnt == $data['limit']) {
             break;
         }
         // keep an eye on the limit
     }
     if ($cnt === 0) {
         $this->nullList($data, $clist, $R);
         return true;
     }
     $R->doc .= $this->preList($clist, $data);
     foreach ($rows as $row) {
         // build data rows
         $R->doc .= $this->before_item;
         foreach ($row as $num => $cval) {
             if ($clist[$num] !== "%pageid%") {
                 // print title
                 $R->doc .= "<br>";
                 $R->doc .= $this->before_title;
                 $R->doc .= $clist[$num];
                 $R->doc .= ": ";
                 $R->doc .= $this->after_title;
             }
             // print val
             $R->doc .= $this->before_val;
             $R->doc .= $this->dthlp->_formatData($data['cols'][$clist[$num]], $cval, $R);
             $R->doc .= $this->after_val;
         }
         $R->doc .= $this->after_item;
     }
     $R->doc .= $this->postList($data, sqlite_num_rows($res));
     return true;
 }
 function getAllContents($file)
 {
     $db = sqlite_open($file);
     $rs = sqlite_query('SELECT * FROM trans_unit', $db);
     $result = '';
     while ($row = sqlite_fetch_array($rs, SQLITE_NUM)) {
         $result .= implode(', ', $row) . "\n";
     }
     sqlite_close($db);
     return $result;
 }
Example #19
0
function fetch_assoc($query_results)
{
    if (DATABASE_TYPE == "mysql") {
        $results = mysqli_fetch_assoc($query_results);
    } elseif (DATABASE_TYPE == "sqlite") {
        $results = sqlite_fetch_array($query_results, SQLITE_ASSOC);
    } elseif (DATABASE_TYPE == "pgsql") {
        $results = pg_fetch_assoc($query_results);
    }
    return $results;
}
 /**
  * 执行一个数据库查询语句,并返回第一行结果
  * @param string $sql
  * @return array
  * @throws Exception
  */
 public function queryAndFetch($sql)
 {
     if (!$this->db) {
         throw new Exception("sqlite db not connected error");
     }
     if ($this->sqlite_version == 2) {
         return sqlite_fetch_array(sqlite_unbuffered_query($this->db, $sql));
     } else {
         return $this->db->query($sql)->fetch();
     }
 }
Example #21
0
function sql_fetch_row($data)
{
    if (defined('DB_TYPE')) {
        if (DB_TYPE == 'mysql') {
            $sql = mysql_fetch_row($data);
        } elseif (DB_TYPE == 'sqlite') {
            $sql = sqlite_fetch_array($data, SQLITE_NUM);
        }
        return $sql;
    }
}
Example #22
0
 protected function db_fetch_wrapper($resource)
 {
     if (in_array($resource, array(null, false, true), true)) {
         $result = false;
     } else {
         if (($result = sqlite_fetch_array($resource, SQLITE_ASSOC)) === null) {
             $result = false;
         }
     }
     return $result;
 }
Example #23
0
function set_pfhost_nonwritable($name)
{
    global $database;
    $db = sqlite_popen($database);
    $results = sqlite_query("select * from pfhosts where name='" . sqlite_escape_string($name) . "'", $db);
    $pfhost_check = sqlite_fetch_array($results, SQLITE_ASSOC);
    if ($pfhost_check['can_connect'] == "true") {
        $results = sqlite_query("update pfhosts set can_connect='false' where name='" . sqlite_escape_string($name) . "'", $db);
    }
    sqlite_close($db);
}
/**
 * Implementation of hook_dirlist.
 */
function ft_fileinfo_dirlist()
{
    global $ft;
    $sql = 'SELECT name, description FROM fileinfo WHERE dir = ' . sqlite_escape_string(ft_get_dir());
    $result = sqlite_query($ft['db']['link'], $sql);
    if ($result) {
        while ($entry = sqlite_fetch_array($query, SQLITE_ASSOC)) {
            $ft['fileinfo']['descriptions'][$entry['file']] = $entry['description'];
        }
    }
}
 /**
  * @throws SQLException
  * @return void
  */
 protected function initTables()
 {
     include_once 'creole/drivers/sqlite/metadata/SQLiteTableInfo.php';
     $sql = "SELECT name FROM sqlite_master WHERE type='table' UNION ALL SELECT name FROM sqlite_temp_master WHERE type='table' ORDER BY name;";
     $result = sqlite_query($this->dblink, $sql);
     if (!$result) {
         throw new SQLException("Could not list tables", sqlite_last_error($this->dblink));
     }
     while ($row = sqlite_fetch_array($result)) {
         $this->tables[strtoupper($row[0])] = new SQLiteTableInfo($this, $row[0]);
     }
 }
Example #26
0
 /**
  * Return an associative array of converted data
  *
  * @return array Associative array of row's data
  */
 protected function fetchRowAssocDb()
 {
     $row = sqlite_fetch_array($this->resource, SQLITE_ASSOC);
     $out = array();
     foreach ($row as $k => $v) {
         if (substr($k, 0, 1) == '"' && substr($k, -1) == '"') {
             $k = substr($k, 1, -1);
         }
         $out[$k] = $v;
     }
     return $out;
 }
Example #27
0
 function fetch($type = SQLITE_BOTH)
 {
     if ($type == 1) {
         $type = SQLITE_ASSOC;
     } elseif ($type == 2) {
         $type = SQLITE_NUM;
     } elseif ($type == 3 || $type != SQLITE_BOTH) {
         $type = SQLITE_BOTH;
     }
     //
     return sqlite_fetch_array($this->query, $type);
 }
Example #28
0
 public function get($module, $identifier)
 {
     $module = sqlite_escape_string($module);
     $identifier = sqlite_escape_string($identifier);
     $results = sqlite_query($this->_db, "SELECT value FROM {$this->_table} WHERE module='{$module}' AND identifier='{$identifier}'");
     $results = sqlite_fetch_array($results);
     if (count($results) == 0) {
         return false;
         // no hit
     }
     return unserialize($results[0]);
 }
Example #29
0
function sql_fetch_array($data)
{
    global $con;
    if (defined('DB_TYPE')) {
        if (DB_TYPE == 'mysql') {
            $sql = mysql_fetch_array($data);
        } elseif (DB_TYPE == 'sqlite') {
            $sql = sqlite_fetch_array($data);
        }
    }
    return $sql;
}
Example #30
0
 public function executeSQL($a_query)
 {
     if (!$this->db) {
         return NULL;
     }
     $result = sqlite_query($this->db, $a_query);
     $res = array();
     while ($temp = sqlite_fetch_array($result)) {
         $res[] = $temp;
     }
     return $res;
 }