我有Mysql数据库,并希望每隔1小时从文件X复制到表Y
我创建代码但无法正常工作 没动
我可以选择3列或4列进行复制并撤回其他列
<?php
$page = $_SERVER['PHP_SELF'];
$sec = "3600";
?>
<html>
<head>
<meta http-equiv="refresh" content="3600">
</head>
<body dir="rtl">
<?php
echo "Update in: ".date("h:i:sa");
echo"<br>";
$mysql_hostname = "localhost";
$mysql_user = "test";
$mysql_password = "test";
$mysql_database = "test";
$dbh = new PDO("mysql:dbname={$mysql_database};host={$mysql_hostname}", $mysql_user, $mysql_password);
if (!$dbh) {
die('Could not connect: ' . mysql_error());
}
else
{
$table_name="x";
$backup_table_name="y";
$query="INSERT INTO `".$backup_table_name."` SELECT * FROM ".$table_name;
$dbh->query($query);
$dbh->query("TRUNCATE `".$table_name."`");
echo "StartUpdate....................<br>";
}
?>
表x是
CREATE TABLE `x` (
`Rates_Rate_Symbol` varchar(8) CHARACTER SET utf8 DEFAULT NULL,
`Rates_Rate_Bid` decimal(10,5) DEFAULT NULL,
`Rates_Rate_Ask` decimal(10,5) DEFAULT NULL,
`Rates_Rate_High` decimal(10,5) DEFAULT NULL,
`Rates_Rate_Low` decimal(10,5) DEFAULT NULL,
`Rates_Rate_Direction` int(11) DEFAULT NULL,
`Rates_Rate_Last` varchar(8) CHARACTER SET utf8 DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
表y我想要它作为备份表
CREATE TABLE `y` (
`Symbol` varchar(8) CHARACTER SET utf8 DEFAULT NULL,
`Bid` decimal(10,5) DEFAULT NULL,
`Ask` decimal(10,5) DEFAULT NULL,
`High` decimal(10,5) DEFAULT NULL,
`Low` decimal(10,5) DEFAULT NULL,
`Direction` int(11) DEFAULT NULL,
`Last` varchar(8) CHARACTER SET utf8 DEFAULT NULL,
`backup_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`IDBC` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`IDBC`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;