0
나는 다음과 같은 기능을 가지고PDO 삽입은 설명 할 수없는 "문자열 변환 배열을"발생 오류
insertIdAfterInsert은()이다public function addProduct($type, $title, $url
, $small_image_id, $large_image_id, $number, $number_type
, $formatted_number, $fk) {
switch (strtoupper($type)) {
case 'FOO':
$ind = 1;
break;
case 'BARR':
$ind = 2;
break;
default:
return null;
}
$sql= "INSERT INTO product(fk_id, type_id, title, url, ".
"sm_image_id, lg_image_id, number, ".
"num_type, num_formatted)".
"values(?, ?, ?, ?, ?, ?, ?, ?, ?)";
return $this->insertIdAfterInsert($sql,'iissiiiss',array($fk
, $ind, $title , $url, $small_image_id
, $large_image_id, $number, $number_type, $formatted_number));
}
:
private function insertIdAfterInsert($sql,$types = null,$params = null) {
$stmt = $this->conn->prepare($sql);
if ($stmt === false) {
trigger_error('Error: ' . $this->conn->errno . ' ' . $this->conn->error, E_USER_ERROR);
}
if($types&&$params)
{
$typeArr = str_split($types);
for($i=0; $i< count($params); $i++) {
if ($typeArr[$i] === 'i') {
$bind_type = PDO::PARAM_INT;
} elseif($typeArr[$i]==='s'){
$bind_type = PDO::PARAM_STR;
}
$stmt->bindValue($i+1, $params[$i], $bind_type);
}
}
echo (var_dump($stmt->debugDumpParams()));
try {
if (!$stmt->execute()) {
trigger_error('Error: ' . $this->conn->errorCode() . ' ' . $this->conn->errorInfo(), E_USER_ERROR);
}
} catch (Exception $e) {
trigger_error('Error: ' . $this->conn->errorCode() . ' ' . $this->conn->errorInfo(), E_USER_ERROR);
}
$stmt = null;
return $this->conn->lastInsertId();
}
UPDATE : 캐치() 오류가 인쇄되는 곳입니다.
내가 전달합니다.
insertIdAfterInsert이insertIdAfterInsert('INSERT INTO aff...', 'iissiiiss', Array)
을 받고 있음을
내 오류가 표시되고 debugDumpParams은 다음과 같습니다
SQL: [183] INSERT INTO affiliate_product(fk_id, type_id, title, url, sm_image_id, lg_image_id, number, num_type, num_formatted)values(?, ?, ?, ?, ?, ?, ?, ?, ?)
Params: 9
Key: Position #0:
paramno=0
name=[0] ""
is_param=1
param_type=1
Key: Position #1:
paramno=1
name=[0] ""
is_param=1
param_type=1
Key: Position #2:
paramno=2
name=[0] ""
is_param=1
param_type=2
Key: Position #3:
paramno=3
name=[0] ""
is_param=1
param_type=2
Key: Position #4:
paramno=4
name=[0] ""
is_param=1
param_type=1
Key: Position #5:
paramno=5
name=[0] ""
is_param=1
param_type=1
Key: Position #6:
paramno=6
name=[0] ""
is_param=1
param_type=1
Key: Position #7:
paramno=7
name=[0] ""
is_param=1
param_type=2
Key: Position #8:
paramno=8
name=[0] ""
is_param=1
param_type=2
NULL
(내가 마지막 NULL에 대해 잘 모르겠지만, 작동하는 인서트를 반향과 동일한 NULL이 표시되어 너무 걱정하지 않아도됩니다.)
"배열을 문자열 변환"으로 왜 던지 말할 수 있습니까?
감사합니다.
하지이었다 오류는 줄 번호를 언급 하는가? – Scopey
['PDO :: errorInfo()'] (http://php.net/manual/pdo.errorinfo.php)가 배열을 반환하지 않습니까? 당신은 당신의'trigger_error' 호출을 연결합니다. – Phil
흥미롭게도, 제 출력물에 실제로 Trigger_error() 메시지가 보이지 않습니다. 그걸 되돌릴 수 있는지 보겠습니다. – hamil10