access時間をinsert

mysql> use redirect
Database changed
mysql> select * from url
-> ;
+—-+——+—————————+
| no | id | url |
+—-+——+—————————+
| 1 | 001 | https://www.facebook.com/ |
| 2 | 002 | https://www.amazon.com/ |
| 3 | 003 | https://www.apple.com |
| 4 | 004 | https://www.google.com |
+—-+——+—————————+
4 rows in set (0.00 sec)

mysql> create table accesstime (
-> no int unsigned auto_increment primary key,
-> id varchar(11),
-> time datetime
-> );
Query OK, 0 rows affected (0.21 sec)

$date = new DateTime();
$datetime = $date->format('Y-m-d H:i:s');
echo $datetime;

if(isset($_GET["id"])){
	$id = $_GET["id"];
} else {
	$id = "001";
}
try {
$pdo = new PDO('mysql:host=localhost;dbname=redirect;charset=utf8','root','',
array(PDO::ATTR_EMULATE_PREPARES => false));
} catch (PDOException $e) {
 exit('データベース接続失敗。'.$e->getMessage());
}
$stmt = $pdo->query("SELECT * FROM url where id = $id");
$row = $stmt -> fetch(PDO::FETCH_ASSOC);
$url = "location: " .$row["url"]. "";


$stmt1 = $pdo -> prepare("INSERT INTO accesstime (id, time) VALUES (:id, :time)");
$stmt1->bindParam(':id', $id, PDO::PARAM_STR);
$stmt1->bindParam(':time', $datetime, PDO::PARAM_STR);

$stmt1->execute();

header($url);

idとaccess時間がtable accesstimeに入ってますね♪
mysql> select * from accesstime;
+—-+——+———————+
| no | id | time |
+—-+——+———————+
| 1 | 001 | 2018-09-19 01:03:54 |
+—-+——+———————+
1 row in set (0.00 sec)

さあ、laravelをやりましょう。