我有以下代码:
function dbInsert()
{
global $dbcon, $dbtable;
global $inputData;
$sqlQuery = 'INSERT INTO ' . $dbtable . ' (id_author, date, title, description) VALUES (?, ?, ?, ?)';
$stmt = $dbcon->prepare($sqlQuery);
echo $sqlQuery;
$stmt->bind_param('isss', $inputData['idAuthor'], $inputData['date'], $inputData['title'], $inputData['description']);
$stmt->execute();
$stmt->close();
header('Location: ./news.php?order=' . $_GET['order'] . '&sort=' . $_GET['sort'] . '&filter=' . $_GET['filter'] . '&page=' . $_GET['page'] . '');
}
$inputData['date'] 的格式为 dd.mm.yyyy ex (18.02.2010)
我找不到日期参数,因此我尝试将其作为字符串插入,对吗?我想我需要告诉 mysql 如何处理输入,但找不到有关该主题的任何内容。 ORACLE 中的等效项是 TO_DATE(?, 'dd.mm.yyyy') 如果它有助于澄清我的要求。
最佳答案
您可以查看STR_TO_DATE功能。它需要一个格式参数。格式参数的允许值描述为 here .
$sqlQuery = 'INSERT INTO ' . $dbtable . ' (id_author, date, title, description)' .
' VALUES (?, STR_TO_DATE(?, \'%d.%m.%Y\'), ?, ?)';
关于php - 如何将日期作为参数插入mysql?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2285231/