PHP Velho Oeste 2024

sqlite_fetch_array

SQLiteResult->fetch

SQLiteUnbuffered->fetch

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0)

sqlite_fetch_array -- SQLiteResult->fetch -- SQLiteUnbuffered->fetchSonuç kümesindeki sonraki satırı bir dizi içinde döndürür

Açıklama

sqlite_fetch_array ( resource $sonuç [, int $sonuç_türü = SQLITE_BOTH [, bool $ikil_çöz = true ]] ) : array

Nesne yönelimli kullanım

fetch ([ int $sonuç_türü = SQLITE_BOTH [, bool $ikil_çöz = true ]] ) : array
fetch ([ int $sonuç_türü = SQLITE_BOTH [, bool $ikil_çöz = true ]] ) : array

sonuç tanıtıcısı ile belirtilen sonuç kümesindeki sonraki satırı bir dizi içinde döndürür. Sonuç kümesindeki sonraki konum geçersizse FALSE, aksi takdirde satır verisini bir ilişkisel dizi olarak döndürür.

Değiştirgeler

sonuç

SQLite sonuç özkaynağı. Nesne yönelimli kullanımda bu değiştirgeye gerek yoktur.

sonuç_türü

İsteğe bağlı bu değiştirgede döndürülen dizinin nasıl oluşturulacağını belirleyen bir sabit belirtilir. SQLITE_ASSOC belirtilirse alanların isimleri indis olarak kullanılır. SQLITE_NUM belirtilirse alanların sıra numaraları indis olarak kullanılır. SQLITE_BOTH için ise hem isimli hem de sayısal indisli bir dizi döner. SQLITE_BOTH bu işlev için öntanımlı değerdir.

ikil_çöz

TRUE belirtildiği takdirde (öntanımlıdır), veriye sqlite_escape_string() işleviyle ikil kodlama uygulanmışsa PHP bunu çözer. SQLite ile işlem yapan başka uygulamalarca oluşturulmuş veritabanları için bir takım ara işlemler yapmıyorsanız, normal olarak bu değeri öntanımlı haliyle bırakmanız gerekir.

Dönen Değerler

Sonuç kümesindeki sonraki konum sonuncu satırın sonrası ise FALSE, aksi takdirde satır verisini bir ilişkisel dizi olarak döndürür.

SQLITE_ASSOC ve SQLITE_BOTH sabitleri kullanılarak döndürülen sütun isimlerinin harf büyüklükleri sqlite.assoc_case php.ini yapılandırma yönergesinin değerine uygun olarak döndürülür.

Örnekler

Örnek 1 - Yordamsal kullanım örneği

<?php
$dbhandle 
sqlite_open('sqlitedb');
$query sqlite_query($dbhandle'SELECT name, email FROM users LIMIT 25');
while (
$entry sqlite_fetch_array($querySQLITE_ASSOC)) {
    echo 
'İsim: ' $entry['name'] . '  Eposta: ' $entry['email'];
}
?>

Örnek 2 - Nesne yönelimli kullanım örneği

<?php
$db 
= new SQLiteDatabase('sqlitedb');

// Tamponlu sonuç kümesi
$sorgu $db->query('SELECT name, email FROM users LIMIT 25');

// Tamponsuz sonuç kümesi
$sorgu $db->unbufferedQuery('SELECT name, email FROM users LIMIT 25');

while (
$entry $sorgu->fetch(SQLITE_ASSOC)) {
    echo 
'İsim: ' $entry['name'] . '  Eposta: ' $entry['email'];
}
?>

Ayrıca Bakınız

add a note add a note

User Contributed Notes 1 note

up
0
saleh at sfsj dot net
19 years ago
[Editor's note: to get short column names there's an undocumented PRAGMA setting. You can exec "PRAGMA short_column_names = ON" to force that behavior.]

I noticed that if you use Joins in SQL queries, the field name is messed up with the dot!
for example if you have this query:
SELECT n.*, m.nickname FROM news AS n, members AS m WHERE n.memberID = m.id;

now if you want to print_r the results returned using SQLITE_ASSOC type, the result array is like this :
array
(
  [n.memberID] => 2
  [n.title] => test title
  [m.nickname] => NeverMind
  [tablename.fieldname] => value
)

and I think it looks horriable to use the variable ,for example, $news['m.nickname'] I just don't like it!

so I've made a small function that will remove the table name (or its Alias) and will return the array after its index is cleaned
<?php
function CleanName($array)
{
  foreach (
$array as $key => $value) {
   
//if you want to keep the old element with its key remove the following line
     
unset($array[$key]);

  
//now we clean the key from the dot and tablename (alise) and set the new element
     
$key = substr($key, strpos($key, '.')+1);
     
$array[$key] = $value;
  }
  return
$array;
}
?>
To Top