O’ zbekiston respublikasi


$dsn = 'mysql:host=localhost;dbname=mydatabase'


Download 83.08 Kb.
bet4/7
Sana18.06.2023
Hajmi83.08 Kb.
#1597836
1   2   3   4   5   6   7
Bog'liq
4-mustaqil ishi.

$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

Download 83.08 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling