Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> pdo - bindowanie / podpinanie wartosci
qbal
post
Post #1





Grupa: Zarejestrowani
Postów: 28
Pomógł: 0
Dołączył: 24.11.2006

Ostrzeżenie: (0%)
-----


Witam

Jestem poczatkujacy w php5. NIe rozumie paru rzeczy odnosnie PDO. Przykladowy skrypt (specjalnie z bledem)

  1. <?php
  2. try {
  3.  
  4.  
  5. $dbh = new PDO('mysql:host=localhost;port=3305;dbname=dbname', 'user', 'pass');
  6. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  7. $stmt= $dbh->prepare('INSERT INTO osoba VALUES(:id,:imie,:email)');
  8.  
  9. $id='nr';
  10. $imie='aaa';
  11. $email='a@a.pl';
  12.  
  13. $stmt->bindValue(':id',$id,PDO::PARAM_INT);
  14. $stmt->bindValue(':imie',$imie,PDO::PARAM_STR);
  15. $stmt->bindValue(':email',$email,PDO::PARAM_STR);
  16. $stmt -> execute();
  17.  
  18. $stmt->closeCursor();
  19. unset($stmt);
  20.  
  21. } catch (Exception $e) {
  22. echo 'Failed: ' . $e->getMessage();
  23. }
  24. ?>

tabela w MySQL qyglada nastepujaco (typ tabeli: InnoDB)
  1. DESC osoba;
  2. +-------+-------------+------+-----+---------+----------------+
  3. | FIELD | Type | NULL | KEY | DEFAULT | Extra |
  4. +-------+-------------+------+-----+---------+----------------+
  5. | id | int(11) | NO | PRI | NULL | AUTO_INCREMENT |
  6. | imie | varchar(10) | YES | | NULL | |
  7. | email | varchar(15) | YES | | NULL | |
  8. +-------+-------------+------+-----+---------+----------------+


Pytania:
1.dlaczego $stmt->bindValue(':id',$id,PDO::PARAM_INT); nie odrzuca wartosci string? przeciez po to sie dodaje ten parametr (PDO::PARAM_INT)
2. Dlaczego MySQL nie odrzuca stringa dla pola id?

uzywam php 5.1.6, baza MySQL 5.0.22
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 24.08.2025 - 17:37