Reputation: 1
I have these query:
$sql="insert into m_ruangan (RG_ID,RG_Nama,RG_Kapasitas,RG_Keterangan,RG_AktifYN,RG_UpdateID,RG_UpdateTime) ".
"values (:field1,:field2,:field3,:field4,:field5,:field6,:field7); ";
$stmt->bindValue(':field1', $result['RG_ID'], PDO::PARAM_INT);
$stmt->bindValue(':field2', $result['RG_Nama'], PDO::PARAM_STR);
$stmt->bindValue(':field3', $result['RG_Kapasitas'], PDO::PARAM_INT);
$stmt->bindValue(':field4', $result['RG_Keterangan'], PDO::PARAM_STR);
$stmt->bindValue(':field5', $result['RG_AktifYN'], PDO::PARAM_STR);
$stmt->bindValue(':field6', $result['RG_UpdateID'], PDO::PARAM_STR);
$stmt->bindValue(':field7', $result['RG_UpdateTime'], PDO::PARAM_STR);
$stmt =$m_f->cdb->prepare($sql);
$stmt->execute();
When I run it it show no error but the value will not inserted in the table. I'm using the looping for inserting
Any idea why it goes wrong?
Upvotes: 0
Views: 416
Reputation: 945
You say you don't see an error. Are you sure you enabled PDO errors?
$connection = new PDO($connection_string);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
You can choose one of these:
PDO::ERRMODE_SILENT: Just set error codes.
PDO::ERRMODE_WARNING: Raise E_WARNING.
PDO::ERRMODE_EXCEPTION: Throw exceptions.
EDIT: I think the comment of Rikesh describes the problem.
Upvotes: 0
Reputation: 26421
You need to prepare
your sql statement prior to bindValue
,
$stmt =$m_f->cdb->prepare($sql);
$stmt->bindValue(':field1', $result['RG_ID'], PDO::PARAM_INT);
$stmt->bindValue(':field2', $result['RG_Nama'], PDO::PARAM_STR);
.........
$stmt->execute();
Upvotes: 2