我需要在mysql表中插入值,但是当我使用传统的pdo方法插入时,DB
中没有记录。
有任何想法吗?
代码:
$ca1 = filter_input(INPUT_POST, 'var1', FILTER_SANITIZE_NUMBER_INT, $options);
$ca2 = filter_input(INPUT_POST, 'var2', FILTER_SANITIZE_STRING, $options);
$ca3 = filter_input(INPUT_POST, 'var3', FILTER_SANITIZE_STRING, $options);
$ca4 = filter_input(INPUT_POST, 'var4', FILTER_SANITIZE_NUMBER_INT,
$options);
$ca5 = filter_input(INPUT_POST, 'var5', FILTER_SANITIZE_STRING, $options);
$oggi = new DateTime();
$oggi->modify('+1 hour');
$ca6 = $oggi->format('Y-m-d H:i:s');
$conn2 = connect();
$stmt2 = $conn2->prepare("INSERT INTO tab1 (field1, field2, field3, field4, field5, field6) values (:var1, :var2, :var3, :var4, :var5, :var6)");
$stmt2->bindValue(':var1', $ca1, PDO::PARAM_INT);
$stmt2->bindParam(':var2', $ca2, PDO::PARAM_STR);
$stmt2->bindParam(':var3', $ca3, PDO::PARAM_STR);
$stmt2->bindParam(':var4', $ca4, PDO::PARAM_INT);
$stmt2->bindParam(':var5', $ca5, PDO::PARAM_STR);
$stmt2->bindParam(':var6', $ca6, PDO::PARAM_STR);
if ( $ca1 != '' && $ca2 != '' && $ca3 != '' && $ca4 != '' && $ca5 != '') {
$stmt2->execute();
echo $stmt2->errorCode().'<br><br>';
unset ($stmt2, $conn2);
}
else
{
echo '<p class="a">Some text</p>';
}