> 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-sorgulama.md).

# Veri Sorgulama

PHP'de veri sorgulama, veritabanı ile iletişim kurarak verileri sorgulama işlemidir. Bu işlem genellikle bir web uygulamasının dinamik içeriği oluşturmak için kullanılır. Örneğin, bir kullanıcının bir web sayfasında gördüğü içerik, bir veritabanından gelen verilere dayanıyor olabilir.

Veritabanı sorguları genellikle SQL (Structured Query Language) kullanılarak yazılır. PHP'de, veritabanı sorguları oluşturmak için SQL ifadelerini kullanabilirsiniz. Veritabanı sorgulama işlemleri genellikle şu adımları içerir:

1. Veritabanına bağlanma: Veritabanı işlemleri için öncelikle bir bağlantı kurmanız gerekir. Bu genellikle mysqli veya PDO (PHP Data Objects) gibi bir veritabanı sürücüsü kullanılarak yapılır.
2. Sorgu oluşturma: Sorgu oluşturma, SQL ifadelerinin kullanılarak verileri sorgulama işlemidir. Bu ifadeler SELECT, INSERT, UPDATE ve DELETE gibi ifadeler olabilir.
3. Sorguyu çalıştırma: Oluşturulan sorgu, mysqli\_query() veya PDO'nun execute() metodları kullanılarak çalıştırılır.
4. Verileri işleme: Sorgu sonucunda elde edilen veriler, PHP'deki dizi veya nesne türüne dönüştürülerek işlenir.

Örnek bir veri sorgulama işlemi aşağıdaki gibi olabilir:

```php
// Veritabanına bağlanma
$servername = "localhost";
$username = "kullanici_adi";
$password = "sifre";
$dbname = "veritabani_adi";

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

// Sorgu oluşturma
$sql = "SELECT id, ad, soyad FROM kullanici";

// Sorguyu çalıştırma
$result = $conn->query($sql);

// Verileri işleme
if ($result->num_rows > 0) {
  // Verileri döngü kullanarak işleme
  while($row = $result->fetch_assoc()) {
    echo "ID: " . $row["id"]. " - Ad: " . $row["ad"]. " " . $row["soyad"]. "<br>";
  }
} else {
  echo "Kayıt bulunamadı.";
}

// Veritabanı bağlantısını kapatma
$conn->close();
```

Bu örnekte, veritabanına bağlanmak için mysqli kullanılmıştır. Bir sorgu oluşturulmuş ve mysqli\_query() yerine $conn->query() kullanılmıştır. Son olarak, döngü kullanarak elde edilen veriler işlenmiştir.


---

# 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-sorgulama.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.
