Tema: PDO pitanje
Pogledajte određenu poruku
Staro 31. 08. 2007.   #1
McChoban
član
Certified
 
Datum učlanjenja: 21.06.2005
Lokacija: Beograd
Poruke: 60
Hvala: 3
4 "Hvala" u 1 poruci
McChoban is on a distinguished road
Angry PDO pitanje

Ok, ovo je metod iz objekta, ocigledno. Ne obazirite se na global $db, ionako je u pitanju test

Naime, update radi savrseno, a insert nece ni da bekne.
Hvatao sam mu i exception (u ovom kodu nema exc. handlinga, ali nije bitno), no nikakav exception nije uhvacen. Samo se nista ne desava pri upisu u bazu... Any ideas???
Hm da, objekat je imao napravljene parametre, nema ID, i kod je prosao froz uslov tamo kuda treba da prodje, samo se nista nije desilo.
Probao sam i sa samo 2 parametra cisto da vidim da ga ne buni neki podatak, ali ne...

PHP kôd:
    public function save() {
        global 
$db;
        if (
$this->id != null) {
            
$sql "update users set  username = :username ,  password = :password ,  email = :email ,  firstName = :firstName ,  lastName = :lastName ,  address = :address ,  city = :city ,  postCode = :postCode ,  country = :country ,  phone = :phone ,  birthDate = :birthDate ,  startYear = :startYear ,  numDogs = :numDogs ,  kennelName = :kennelName ,  isValidated = :isValidated ,  timeCreated = :timeCreated ,  timeModified = :timeModified  where id = :id";
            
$stmt $db->prepare($sql);
            
$stmt->bindParam(':id'$this->id);
            
$stmt->bindParam(':username'$this->username);
            
$stmt->bindParam(':password'$this->password);
            
$stmt->bindParam(':email'$this->email);
            
$stmt->bindParam(':firstName'$this->firstName);
            
$stmt->bindParam(':lastName'$this->lastName);
            
$stmt->bindParam(':address'$this->address);
            
$stmt->bindParam(':city'$this->city);
            
$stmt->bindParam(':postCode'$this->postCode);
            
$stmt->bindParam(':country'$this->country);
            
$stmt->bindParam(':phone'$this->phone);
            
$stmt->bindParam(':birthDate'$this->birthDate);
            
$stmt->bindParam(':startYear'$this->startYear);
            
$stmt->bindParam(':numDogs'$this->numDogs);
            
$stmt->bindParam(':kennelName'$this->kennelName);
            
$stmt->bindParam(':isValidated'$this->isValidated);
            
$stmt->bindParam(':timeCreated'$this->timeCreated);
            
$stmt->bindParam(':timeModified'$this->timeModified);
            
$stmt->execute();
        } else {
            
$sql "insert into users (username, password, email, firstName, lastName, address, city, postCode, country, phone, birthDate, startYear, numDogs, kennelName, isValidated, timeCreated, timeModified) values (:username, :password, :email, :firstName, :lastName, :address, :city, :postCode, :country, :phone, :birthDate, :startYear, :numDogs, :kennelName, :isValidated, :timeCreated, :timeModified)";
            
$stmt $db->prepare($sql);
            
$stmt->bindParam(':username'$this->username);
            
$stmt->bindParam(':password'$this->password);
            
$stmt->bindParam(':email'$this->email);
            
$stmt->bindParam(':firstName'$this->firstName);
            
$stmt->bindParam(':lastName'$this->lastName);
            
$stmt->bindParam(':address'$this->address);
            
$stmt->bindParam(':city'$this->city);
            
$stmt->bindParam(':postCode'$this->postCode);
            
$stmt->bindParam(':country'$this->country);
            
$stmt->bindParam(':phone'$this->phone);
            
$stmt->bindParam(':birthDate'$this->birthDate);
            
$stmt->bindParam(':startYear'$this->startYear);
            
$stmt->bindParam(':numDogs'$this->numDogs);
            
$stmt->bindParam(':kennelName'$this->kennelName);
            
$stmt->bindParam(':isValidated'$this->isValidated);
            
$stmt->bindParam(':timeCreated'$this->timeCreated);
            
$stmt->bindParam(':timeModified'$this->timeModified);
            
$stmt->execute();
            
$this->setId($db->lastInsertId());
        }
    } 
McChoban je offline   Odgovorite uz citat