我正在尝试通过API向我的数据库添加作业信息。
我的一个Feed提供了一个日期(已发布)和一个到期日期。
我正在尝试插入两个字段(以及其他字段)。
日期输入正常,但是到期日期设置为默认的00:00:00
来自api的示例数据:
{
"jobId":30081256,
"expirationDate":"22/08/2016",
"date":"11/07/2016"
}
我解析准备好输入的日期:
$job_date = $job->date;
$timestamp = strtotime(str_replace('/', '-', $job_date));
$date = date("Y-m-d H:i:s", $timestamp);
//expiry
$job_expiry = $job->expirationDate;
$expiry_timestamp = strtotime(str_replace('/', '-', $job_expiry));
$expiry_date = date("Y-m-d H:i:s", $expiry_timestamp);
当我回复$ date和$ expiry_date的结果时,我得到:
2016-07-11 00:00:00
和
2016-08-22 00:00:00
对我来说看起来都很好,日期的格式为sql所期望的,但是到期日期没有设置。
我不确定它是否与我的查询有关(缩写为显示相关字段 - 所有其他字段都正确插入):
"INSERT INTO
jobs2 (jobref, date, expiry)
VALUES ('"
.$jobref
."','"
.$date
."','"
.$expiry_date
."') ON DUPLICATE KEY UPDATE
`date` = VALUES(date),
`expiry` = VALUES(expiry)"
也许ON DUPLICATE部分?该作业可能已经存在于我的数据库中,但有时它已被刷新/更新,并且发布的日期或到期日可能不同,因此我希望使用API中的最新值更新它们。
这是怎么回事?
表格请求:
CREATE TABLE `jobs2` (
`date` datetime NOT NULL,
`title` varchar(200) COLLATE latin1_general_ci NOT NULL,
`company` varchar(100) COLLATE latin1_general_ci NOT NULL,
`email` varchar(100) COLLATE latin1_general_ci NOT NULL,
`url` varchar(1200) COLLATE latin1_general_ci NOT NULL,
`salarymin` int(20) DEFAULT NULL,
`salarymax` int(20) DEFAULT NULL,
`benefits` varchar(100) COLLATE latin1_general_ci NOT NULL,
`salary` varchar(200) COLLATE latin1_general_ci DEFAULT NULL,
`jobtype` varchar(30) COLLATE latin1_general_ci DEFAULT NULL,
`full_part` varchar(30) COLLATE latin1_general_ci DEFAULT NULL,
`salary_per` varchar(20) COLLATE latin1_general_ci DEFAULT NULL,
`location` varchar(100) COLLATE latin1_general_ci DEFAULT NULL,
`country` varchar(30) COLLATE latin1_general_ci NOT NULL,
`description` varchar(3000) COLLATE latin1_general_ci NOT NULL,
`category` varchar(100) COLLATE latin1_general_ci DEFAULT NULL,
`image` varchar(150) COLLATE latin1_general_ci NOT NULL,
`latitude` float NOT NULL,
`longitude` float NOT NULL,
`town` varchar(50) COLLATE latin1_general_ci NOT NULL,
`county` varchar(50) COLLATE latin1_general_ci NOT NULL,
`location_id` varchar(255) COLLATE latin1_general_ci NOT NULL,
`jobref` varchar(100) COLLATE latin1_general_ci NOT NULL,
`partner` varchar(30) COLLATE latin1_general_ci DEFAULT NULL,
`company_id` int(20) DEFAULT NULL,
`featured` varchar(10) COLLATE latin1_general_ci DEFAULT NULL,
`solr_stored` int(1) DEFAULT NULL,
`expiry` datetime NOT NULL,
UNIQUE KEY `location_id` (`location_id`),
KEY `partner` (`partner`),
KEY `company` (`company`),
KEY `title` (`title`),
KEY `company` (`company`),
KEY `longitude` (`longitude`),
KEY `latitude` (`latitude`),
KEY `jobref` (`jobref`),
KEY `jobtype` (`jobtype`),
KEY `company_id` (`company_id`),
KEY `salarymin` (`salarymin`),
KEY `salarymax` (`salarymax`),
KEY `salary_per` (`salary_per`),
KEY `date` (`date`),
FULLTEXT KEY `title` (`title`),
FULLTEXT KEY `company` (`company`),
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci