2010-07-16 1 views
1

내가

function AddProducts($aTitle, $aDescription, $aPrice, $aQty, $aPhoto) 
    { 

     try { 
      $stmt = $this->pdo->prepare("INSERT INTO products(title, price, description, qty, photo) VALUES(:title, :price, :description, :qty, :photo)"); 
      if(!$stmt){ 
       $err = $this->pdo->errorInfo(); 
       throw new RuntimeException('PRODUCT INSERT FAILED: '.$err[2]); 
      } 
      $stmt->bindValue(':title', $this->title, PDO::PARAM_STR); 
      $stmt->bindValue(':description', $this->description, PDO::PARAM_STR); 
      $stmt->bindValue(':price', $this->price, PDO::PARAM_INT); 
      $stmt->bindValue(':qty', $this->qty, PDO::PARAM_INT); 
      $stmt->bindValue(':photo', $this->photo, PDO::PARAM_STR); 
      $stmt->execute(); 
     }catch (PDOException $e) { 
      echo $e->getMessage(); 
     } 


    } 

$addProducts = $database->AddProducts('Ford Mustang', 'This is a Descriptiom', 299.99, 1, 'images/includes/5.jpg'); 

데이터베이스 클래스와 데이터베이스 통화 기능 작업을 사용하고있는 코드입니다. 또한 지체 된 점을 지적 해 주시면 그것을 배우기 위해 노력하고 있습니다.

+0

어디에서 $ this-> photo를 할당하고 있습니까? 여기에있는 스 니펫에는 없습니다 ... 실제로 모든 값을 메서드의 인수로 전달하지만 실제로는 –

답변

3

$this->photo입니까? 너 정말 너의 수업에이 물건이 있니? 아니면 이런 식으로해야할까요?

function AddProducts($aTitle, $aDescription, $aPrice, $aQty, $aPhoto) 
{ 

    try { 
     $stmt = $this->pdo->prepare("INSERT INTO products(title, price, description, qty, photo) VALUES(:title, :price, :description, :qty, :photo)"); 
     if(!$stmt){ 
      $err = $this->pdo->errorInfo(); 
      throw new RuntimeException('PRODUCT INSERT FAILED: '.$err[2]); 
     } 
     $stmt->bindValue(':title', $aTitle, PDO::PARAM_STR); 
     $stmt->bindValue(':description', $aDescription, PDO::PARAM_STR); 
     $stmt->bindValue(':price', $aPrice, PDO::PARAM_INT); 
     $stmt->bindValue(':qty', $aQty, PDO::PARAM_INT); 
     $stmt->bindValue(':photo', $aPhoto, PDO::PARAM_STR); 
     $stmt->execute(); 
    }catch (PDOException $e) { 
     echo $e->getMessage(); 
    } 


} 

$addProducts = $database->AddProducts('Ford Mustang', 'This is a Descriptiom', 299.99, 1, 'images/includes/5.jpg'); 
+0

+1을 사용하지 않는 것이 논리로 보입니다. – DrColossos

+0

고맙습니다. 완벽했습니다. 미안하지만 여전히 배우기. – thatmediaguy