> For the complete documentation index, see [llms.txt](https://docs.layraweb.com.tr/merhaba/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.layraweb.com.tr/merhaba/php-tarafi/konular/veritabani-islemleri/veri-okuma.md).

# Veri Okuma

PHP'de veritabanı işlemleri için en sık kullanılan yöntemlerden biri veri okuma (select) işlemidir. Bu işlem, belirtilen koşullara göre veritabanındaki verileri seçerek kullanıcının görüntüleyebileceği bir sonuç kümesi döndürür.

Veri okuma işlemini gerçekleştirmek için, öncelikle bir veritabanı bağlantısı oluşturulmalıdır. Bu bağlantıyı oluşturmak için PDO (PHP Data Objects) veya mysqli gibi bir veritabanı sürücüsü kullanılabilir.

Örneğin, mysqli sürücüsü kullanarak bir veritabanı bağlantısı oluşturmak ve bir select sorgusu yürütmek için aşağıdaki gibi bir kod kullanılabilir:

```php
// Veritabanı bağlantısı oluşturma
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

$conn = new mysqli($servername, $username, $password, $dbname);

// Bağlantıyı kontrol etme
if ($conn->connect_error) {
    die("Bağlantı hatası: " . $conn->connect_error);
}

// Select sorgusu
$sql = "SELECT id, ad, soyad FROM kullanicilar";

// Sorguyu yürütme ve sonuç kümesini alma
$result = $conn->query($sql);

// Sonuç kümesindeki verileri işleme
if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["id"]. " - Ad: " . $row["ad"]. " " . $row["soyad"]. "<br>";
    }
} else {
    echo "0 sonuç";
}

// Bağlantıyı kapatma
$conn->close();
```

Bu kod örneği, "kullanicilar" tablosundaki tüm kayıtları seçer ve sonuçları ekrana yazdırır. Veri okuma işlemi için yapılan sorgu, "SELECT" ifadesiyle başlar ve "FROM" ifadesiyle hangi tablodan verilerin seçileceği belirtilir. Bu sorguda herhangi bir koşul belirtilmediği için, tüm kayıtlar seçilir. Eğer sadece belirli koşulları sağlayan kayıtları seçmek istiyorsak, "WHERE" ifadesi kullanarak koşullar belirleyebiliriz.

Sonuç kümesi alındıktan sonra, while döngüsü ile her bir kayıt ayrı ayrı işlenir ve ekrana yazdırılır. Eğer sonuç kümesinde hiç kayıt yoksa, "0 sonuç" mesajı görüntülenir.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.layraweb.com.tr/merhaba/php-tarafi/konular/veritabani-islemleri/veri-okuma.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
