2014-03-07 9 views
0

PDOM 문을 실행할 수 없습니다 여기에 잘못된 정보를 알려주십시오. 내 진술을 MySQL 데이터베이스로 실행할 수 없습니다. 오류가 나타나지 않습니다.도와주세요.

데이터를 배열로 가져 와서 개체로 전달하고 문을 실행하려고합니다.

$query = $db->prepare("INSERT INTO courses (
category_id_fk, 
course_title, 
course_header_title, 
course_header_text, 
course_header_image, 
course_header_video, 
course_slogan_text, 
course_slogan_button_text, 
course_description, 
course_content, 
category_active 
) 
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); 
} 

try{ 
$query->execute(array(
$data["category_name"], 
$data["course_title"], 
$data["course_header_title"], 
$data["course_header_text"], 
$data["course_header_image"]["name"], 
$data["course_header_video"], 
$data["course_slogan_text"], 
$data["course_slogan_button_text"], 
$data["course_description"], 
$data["course_content"], $data["category_active"] 
)); 


}catch(PDOException $e){ 
echo $e->getMessage(); 
} 

if($query->rowCount() == 1){ 

header("Location: courses?msg=success"); 


}else{ 
echo "error"; 
} 

답변

1

오류 모드를 먼저 예외로 확인해야합니다.

$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
+0

'PDO :: setAttribute'는 두 개의 인수를 취합니다 – Phil

+0

@ Phil 고마워요. phil :) – xdazz

1

내 사용자 동의안!

$ db-> setAttribute (PDO :: ATTR_ERRMODE, PDO :: ERRMODE_EXCEPTION);

이것은 진술을 실행할 때 나에게 무엇이 잘못되었는지를 보여주었습니다. 내 문제는 : 잘못된 필드 이름입니다.

+1

하지만 이미 답변을 듣고 있습니다. – Rikesh