$dsn = 'mysql:host=localhost;dbname=mydatabase';
$username = 'username';
$password = 'password';
try {
$db = new PDO($dsn, $username, $password);
} catch (PDOException $e) {
echo 'Xatolik: ' . $e->getMessage();
}
2. So'rov yuborish:
```php
$query = "SELECT * FROM users";
$stmt = $db->query($query);
3. Natijalarni qabul qilish:
```php
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$name = $row['name'];
$email = $row['email'];
// Ma'lumotlarni ishlash...
}
4. Parametrlangan so'rov yuborish:
```php
$query = "SELECT * FROM users WHERE id = :id";
$stmt = $db->prepare($query);
$stmt->bindParam(':id', $userId);
$stmt->execute();
5. Ma'lumot qo'shish:
```php
$query = "INSERT INTO users (name, email) VALUES (:name, :email)";
$stmt = $db->prepare($query);
$stmt->bindParam(':name', $name);
$stmt->bindParam(':email', $email);
$stmt->execute();
6. Ma'lumotni yangilash:
```php
$query = "UPDATE users SET name = :name, email = :email WHERE id = :id";
$stmt = $db->prepare($query);
$stmt->bindParam(':name', $name);
$stmt->bindParam(':email', $email);
$stmt->bindParam(':id', $userId);
$stmt->execute();
7. Ma'lumotni o'chirish:
```php
$query = "DELETE FROM users WHERE id = :id";
$stmt = $db->prepare($query);
$stmt->bindParam(':id', $userId);
$stmt->execute();
PHPda PDO texnologiyasini ishlatish orqali ma'lumotlarni ma'lumotlar bazisi bilan bog'lash va so'rov yuborish oson va xavfsiz bo'ladi. PDO hamda parametrlangan so'rovlarni ishlatish ma'lumotlarni to'g'ridan-to'g'ri o'zgartirish va o'chirish imkoniyatini beradi.
5.PHPda Captcha generatsiya qilish usulla
PHP-da Captcha generatsiya qilish uchun turli usullar mavjud. Quyidagi misol kodlarda bir nechta oddiy Captcha generatsiya usullarini ko'rsataman:
1. Matn asosida Captcha generatsiya qilish:
```php
Do'stlaringiz bilan baham: |