如何在PHP中使用函数NOW() [英] How use the function NOW() in PHP
问题描述
我有一个临时表SQL。我有一个文件,该文件提供了通过 get_current_user
修改了任何信息的用户的名称。
我添加了另一个字段 type = DATETIME
来恢复用户修改的日期和小时。
I have a temporary table SQL. I have a filed that give me the name of the user that modified any information by get_current_user
.
I added another field type=DATETIME
to recovre the date and the hour of the user modifcation.
在 PHP
中,我像所有函数一样添加了它,但是出现了错误。
代码如下:
In PHP
I added it like all my function, but it got an error.
The code is the following:
$sql = "INSERT INTO `...`.`correspondants_bis`
(`code_client` , `name`, `surname` ,`phone`, `fax`, `email`, `added_by`, `Date`, `condition`)
VALUES ('" . $correspondent->getCodeClient() . "',
'" . str_replace("'", "''", $correspondent->getName()) . "',
'" . str_replace("'", "''", $correspondent->getSurname()) . "',
'" . $correspondent->getPhone() . "',
'" . $correspondent->getFax() . "',
'" . $correspondent->getEmail() . "',
'" . $user . "','" . NOW() . "',
'1'
);";
错误是:
Fatal error: Call to undefined function.....
Attempted to call function "NOW" from namespace....
我知道NOW()是 SQL函数
,仅举一个插入
,因为我不知道如何添加它,并且在我的 select函数
之后:
I know that NOW() is an SQL function
, just I got you an example of insert
because I don't know how I add it, and this following my select function
:
public function getCorrespondentByIdBis($id) {
$statement = "SELECT * FROM `correspondants_bis` WHERE `id`='" . $id . "'";
$result = $this->_db->query($statement);
while ($data = $result->fetch()) {
$correspondent = new CorrespondentBis($data['id'], $data['code_client'], $data['name'], $data['surname'], $data['phone'], $data['fax'], $data['email'], get_current_user(), NOW(), 0);
}
}
return $correspondent;
}
请告诉我,我如何更改代码以解决此问题?
Can you tell me please, how I can change my code to resolve this issue ?
推荐答案
现在不是php函数,请替换
now is not php function so replace
NOW()
至
date('Y-m-d H:i:s')
所以您的最终代码
$correspondent = new CorrespondentBis($data['id'], $data['code_client'], $data['name'], $data['surname'], $data['phone'], $data['fax'], $data['email'], get_current_user(), date('Y-m-d H:i:s'), 0);
2。无需使用quote,只需使用 NOW()
所以您的最终查询
2.no need to use quote , just use NOW()
so your final query
$sql = "INSERT INTO `...`.`correspondants_bis`
(`code_client` , `name`, `surname` ,`phone`, `fax`, `email`, `added_by`, `Date`, `condition`)
VALUES ('" . $correspondent->getCodeClient() . "',
'" . str_replace("'", "''", $correspondent->getName()) . "',
'" . str_replace("'", "''", $correspondent->getSurname()) . "',
'" . $correspondent->getPhone() . "',
'" . $correspondent->getFax() . "',
'" . $correspondent->getEmail() . "',
'" . $user . "',
NOW(),
'1'
);";
了解更多信息
http://www.mysqltutorial.org/mysql-now/
这篇关于如何在PHP中使用函数NOW()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!