function result($resultSet, $targetRow, $targetColumn = "") { if (!$resultSet) { return false; } if ($this->conn) { if ($this->method == "pdo") { if ($targetColumn) { $resultRow = $resultSet->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_ABS, $targetRow); return $resultRow[$targetColumn]; } else { $resultRow = $resultSet->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_ABS, $targetRow); return $resultRow[0]; } } else { if ($this->method == "mysql") { return mysql_result($resultSet, $targetRow, $targetColumn); } else { if ($this->method == "sqlite") { return sqlite_column($resultSet, $targetColumn); } } } } }
function sqlitem_column($result, $index_or_name, $decode_binary = TRUE) { return sqlite_column($result, $index_or_name, $decode_binary); }
sqlite_exec($fs, $query); } // // Injection des données en provenance de la base MySQL // $db = WaDatabase($dsn); $tableList = array('wa_abo_liste', 'wa_abonnes', 'wa_admin', 'wa_auth_admin', 'wa_ban_list', 'wa_config', 'wa_forbidden_ext', 'wa_joined_files', 'wa_liste', 'wa_log', 'wa_log_files'); $tableList = str_replace('wa_', $prefixe, $tableList); foreach ($tableList as $table) { printf("Populate table %s...\n", $table); flush(); $fields = array(); $result = sqlite_query($fs, "PRAGMA table_info({$table})"); for ($i = 0, $m = sqlite_num_rows($result); $i < $m; $i++) { sqlite_seek($result, $i); array_push($fields, sqlite_column($result, 'name')); } $fields = implode(', ', $fields); $result = $db->query("SELECT {$fields} FROM {$table}"); $result->setFetchMode(SQL_FETCH_NUM); $numrows = 0; while ($row = $result->fetch()) { $values = array(); $numrows++; foreach ($row as $value) { if (is_null($value)) { $value = 'NULL'; } else { $value = "'" . sqlite_escape_string($value) . "'"; } array_push($values, $value);
function result($resultSet, $targetRow, $targetColumn = "") { if (!$resultSet) { return false; } if ($this->conn) { if ($this->method == "mysql") { return mysql_result($resultSet, $targetRow, $targetColumn); } else { if ($this->method == "sqlite") { return sqlite_column($resultSet, $targetColumn); } } } }
/** * Fetch field * if rownum is false, the current row is used, else it is pointing to the row (zero-based) */ function sql_fetchfield($field, $rownum = false, $query_id = false) { if (!$query_id) { $query_id = $this->query_result; } if ($query_id) { if ($rownum === false) { return @sqlite_column($query_id, $field); } else { $this->sql_rowseek($rownum, $query_id); return @sqlite_column($query_id, $field); } } return false; }
} sqlite_exec("DROP TABLE strings", $db); ///// $data = array(array(0 => 'one', 1 => 'two'), array(0 => 'three', 1 => 'four')); sqlite_query("CREATE TABLE strings(a VARCHAR, b VARCHAR)", $db); foreach ($data as $str) { sqlite_query("INSERT INTO strings VALUES('{$str[0]}','{$str[1]}')", $db); } echo "====BUFFERED====\n"; $r = sqlite_query("SELECT a, b from strings", $db); while (sqlite_valid($r)) { var_dump(sqlite_current($r, SQLITE_NUM)); var_dump(sqlite_column($r, 0)); var_dump(sqlite_column($r, 1)); var_dump(sqlite_column($r, 'a')); var_dump(sqlite_column($r, 'b')); sqlite_next($r); } /// XXX this doesn't match PHP5, but ours looks more correct?? /* echo "====UNBUFFERED====\n"; $r = sqlite_unbuffered_query("SELECT a, b from strings", $db); while (sqlite_valid($r)) { var_dump(sqlite_current($r, SQLITE_NUM)); var_dump(sqlite_column($r, 0)); var_dump(sqlite_column($r, 'b')); var_dump(sqlite_column($r, 1)); var_dump(sqlite_column($r, 'a')); sqlite_next($r); } */
function sql_fetchfield($field, $rownum = -1, $query_id = 0) { if (!$query_id) { $query_id = $this->query_result; } if ($query_id) { return $rownum > -1 ? @sqlite_seek($query_id, $rownum) ? @sqlite_column($query_id, $field) : false : @sqlite_column($query_id, $field); } }
$result = sqlite_current($rh); var_dump($result); $b = sqlite_has_prev($rh); echo "has_prev?\n"; var_dump($b); // // if (function_exists('sqlite_key')) // echo "on row: ".sqlite_key($rh)."\n"; } // columns sqlite_seek($rh, 2); for ($i = 0; $i < sqlite_num_fields($rh); $i++) { $n = sqlite_field_name($rh, $i); $c = sqlite_column($rh, $i); var_dump($c); $c = sqlite_column($rh, $n); var_dump($c); } // fetch_all $r = sqlite_fetch_all($rh); var_dump($r); // fetch single sqlite_rewind($rh); $r = sqlite_fetch_string($rh); var_dump($r); } else { echo "bad query: " . sqlite_error_string($db); } // array_query $val = sqlite_array_query($db, 'SELECT * FROM mytable'); var_dump($val);