

{"id":1395,"date":"2018-12-27T18:02:39","date_gmt":"2018-12-27T09:02:39","guid":{"rendered":"https:\/\/curecode.jp\/tech\/?p=1395"},"modified":"2018-12-27T18:02:39","modified_gmt":"2018-12-27T09:02:39","slug":"fuelphp-simpleauth-error-on-mysql-sql_mode-strict","status":"publish","type":"post","link":"https:\/\/curecode.jp\/tech\/fuelphp-simpleauth-error-on-mysql-sql_mode-strict\/","title":{"rendered":"FuelPHP SimpleAuth \u306e\u5bfe\u8c61\u30c6\u30fc\u30d6\u30eb\u3067 updated_at \u3092 DATETIME \u578b\u306b\u3059\u308b\u3068\u767a\u751f\u3059\u308b SQL \u30a8\u30e9\u30fc\u306e\u56de\u907f\u65b9\u6cd5"},"content":{"rendered":"<h3>\u524d\u63d0\u6761\u4ef6<\/h3>\n<h4>SimpleAuth<\/h4>\n<p>\n FuelPHP \u306e Auth \u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u9644\u5c5e\u3057\u3066\u3044\u308b <a href=\"http:\/\/fuelphp.jp\/docs\/1.8\/packages\/auth\/simpleauth\/usage.html\" target=\"_blank\">SimpleAuth<\/a> \u306f\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u4f7f\u3063\u305f\u8a8d\u8a3c\u30b7\u30b9\u30c6\u30e0\u3092\u69cb\u7bc9\u3059\u308b\u306e\u306b\u4fbf\u5229\u306a\u6a5f\u80fd\u3092\u6301\u3063\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u305d\u306e\u307e\u307e\u5229\u7528\u3057\u3066\u3044\u308b\u30b1\u30fc\u30b9\u3082\u591a\u3044\u3068\u601d\u3044\u307e\u3059\u3002\n<\/p>\n<p>\n  SimpleAuth \u306f config\/simpleauth.php \u3067 <var>table_name<\/var> \u306b\u8a2d\u5b9a\u3057\u305f\u30c6\u30fc\u30d6\u30eb\u3092\u5229\u7528\u3057\u307e\u3059\u3002\uff08\u30c7\u30d5\u30a9\u30eb\u30c8\u306f <code>\"users\"<\/code>\u3002\uff09\u3053\u306e\u30c6\u30fc\u30d6\u30eb\u306e\u5b9a\u7fa9\u3092\u4f5c\u6210\u3059\u308b\u30b3\u30de\u30f3\u30c9\u3082 Auth \u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u542b\u307e\u308c\u3066\u3044\u3066\u6b21\u306e\u3088\u3046\u306b\u3059\u308b\u3053\u3068\u3067 migration \u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002\n<\/p>\n<pre><code class=\"bash\">\r\n$ oil refine migrate --packages=auth\r\n<\/code><\/pre>\n<h4>DATETIME \u578b<\/h4>\n<p>\n  \u4e00\u65b9\u3001FuelPHP \u306e\u30c6\u30fc\u30d6\u30eb\u5b9a\u7fa9\u306b\u306f created_at \u3068 updated_at \u3068\u3044\u3046\u9805\u76ee\u304c\u542b\u307e\u308c\u3001\u3053\u306e\u578b\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u3067 int(11) \u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002\u3053\u308c\u3092 MySQL \u306e TIMESTAMPE \u578b\u3001\u3042\u308b\u3044\u306f\u3001DATETIME \u578b\u306b\u5bfe\u5fdc\u3055\u305b\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002\u3088\u304f\u77e5\u3089\u308c\u3066\u3044\u308b\u3088\u3046\u306b\u3001\u5bfe\u5fdc\u3059\u308b\u30e2\u30c7\u30eb\u306e Model_Crud \u3092\u7d99\u627f\u3057\u305f\u30af\u30e9\u30b9\u3067\u3001 \u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002\n<\/p>\n<pre><code class=\"php\">\r\nclass Model_User extends Model_Crud\r\n{\r\n    protected static $_table_name = 'users';\r\n    protected static $_created_at = 'created_at';\r\n    protected static $_updated_at = 'updated_at';\r\n    \/\/DB\u304cunix_timestamp \u3067\u306f\u306a\u304f MySQL \u306e timestamp\/datetime \u578b\u306b\u3059\u308b\r\n    protected static $_mysql_timestamp = true;\r\n<\/code><\/pre>\n<p>\n  \u3053\u306e\u3088\u3046\u306b users \u30c6\u30fc\u30d6\u30eb\u306e created_at, updated_at \u3092 DATETIME \u578b\u306b\u5909\u66f4\u3057\u3066\u3082\u3001\u3053\u308c\u307e\u3067\u306f SimpleAuth \u3092\u4f7f\u3048\u3066\u3044\u307e\u3057\u305f\u3002\n<\/p>\n<h3>MaraiDB \u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u4e0a\u3052\u305f\u3089\u30a8\u30e9\u30fc\u304c\u767a\u751f<\/h3>\n<p>\n  \u3057\u304b\u3057\u3001MaraiDB \u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3092 10.1 \u7cfb\u304b\u3089 10.2 \u7cfb\u306b\u4e0a\u3052\u305f\u969b\u306b\u3001SimpaleAuth \u306e <code class=\"php\">create_user<\/code> \u3084 <code class=\"php\">update_user<\/code> \u3067 SQL \u306e\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002\u30a8\u30e9\u30fc\u306e\u5185\u5bb9\u306f\u6b21\u306e\u3088\u3046\u306a\u3082\u306e\u3067\u3059\u3002\n<\/p>\n<pre><code class=\"php\">\r\nSQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value:\r\n '1545375841' for column 'updated_at' at row 1 with query: \r\n   \"UPDATE `users` SET `password` = '************************', `updated_at` = 1545375841 \r\n   WHERE `username` = '******'\" \r\n in \/*********\/fuel\/core\/classes\/database\/pdo\/connection.php on line 223\r\n<\/code><\/pre>\n<p>\n  &#8216;updated_at&#8217; \u306f DATETIME \u578b\u306a\u306e\u306b int(11) \u306e\u5024\u3092\u30bb\u30c3\u30c8\u3057\u3088\u3046\u3068\u3057\u3066\u30a8\u30e9\u30fc\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002\n<\/p>\n<h3>SQL \u30e2\u30fc\u30c9\u306e\u78ba\u8a8d<\/h3>\n<p>\n  \u3053\u308c\u306f\u3001MaraiDB \u3092 10.2 \u306b\u4e0a\u3052\u305f\u3053\u3068\u3067\u3001sql_mode \u3068\u3044\u3046\u5909\u6570\u306e\u521d\u671f\u5024\u304c\u5909\u308f\u3063\u305f\u3053\u3068\u304c\u304d\u3063\u304b\u3051\u3067\u51fa\u3066\u3044\u307e\u3057\u305f\u3002<kbd>SHOW VARIABLES<\/kbd> \u3067 <var>sql_mode<\/var> \u306e\u5024\u3092\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3059\u3002\n<\/p>\n<h4>MariaDB 10.1 (\u30a8\u30e9\u30fc\u7121\u3057)<\/h4>\n<pre><code class=\"sql\">\r\nMariaDB [(none)]> SHOW VARIABLES LIKE \"%sql_mode%\";\r\n+---------------+--------------------------------------------+\r\n| Variable_name | Value                                      |\r\n+---------------+--------------------------------------------+\r\n| sql_mode      | NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |\r\n+---------------+--------------------------------------------+\r\n1 row in set (0.00 sec)\r\n<\/code><\/pre>\n<p>SQL \u30e2\u30fc\u30c9\u306b <samp>STRICT_TRANS_TABLES<\/samp> \u306f\u542b\u307e\u308c\u3066\u3044\u307e\u305b\u3093\u3002<\/p>\n<h4>MariaDB 10.2 (\u30a8\u30e9\u30fc\u3042\u308a)<\/h4>\n<pre><code class=\"sql\">\r\nMariaDB [(none)]> SHOW VARIABLES LIKE \"%sql_mode%\";\r\n+---------------+-------------------------------------------------------------------------------------------+\r\n| Variable_name | Value                                                                                     |\r\n+---------------+-------------------------------------------------------------------------------------------+\r\n| sql_mode      | STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |\r\n+---------------+-------------------------------------------------------------------------------------------+\r\n1 row in set (0.00 sec)\r\n<\/code><\/pre>\n<p>\n  MariaDB 10.2 \u306e\u521d\u671f\u8a2d\u5b9a\u3067 SQL\u30e2\u30fc\u30c9\u306b <samp>STRICT_TRANS_TABLES<\/samp> \u304c\u52a0\u308f\u3063\u305f\u3053\u3068\u3067\u3001\u3053\u308c\u307e\u3067 UNIX \u30bf\u30a4\u30e0\u30b9\u30bf\u30f3\u30d7\u306e int \u578b\u304c\u81ea\u52d5\u7684\u306b DATETIME \u578b\u306b\u7f6e\u304d\u63db\u308f\u3063\u3066\u3044\u305f\u30b1\u30fc\u30b9\u304c\u3001\u30a8\u30e9\u30fc\u306b\u306a\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u3088\u3046\u3067\u3059\u3002\n<\/p>\n<p>\n  MariaDB 10.2 \u3060\u3051\u3067\u306a\u304f\u3001MySQL 5.6 \u3067\u3082 <var>sql_mode<\/var> \u306e\u521d\u671f\u5024\u306f <samp>STRICT_TRANS_TABLES<\/samp>\u3067\u3059\u3002\n<\/p>\n<h3>SQL \u30e2\u30fc\u30c9\u306e\u5909\u66f4\u3067\u56de\u907f<\/h3>\n<p>\n MaraiDB \u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb  \/etc\/my.cnf \u3092\u7de8\u96c6\u3057\u3066\u3001<var>sql_mode<\/var> \u3092\u5909\u66f4\u3057\u307e\u3059\u3002\n<\/p>\n<pre><code class=\"ini\">\r\n[mysqld]\r\n...\r\nsql_mode='NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'\r\n<\/code><\/pre>\n<p>\n  MariaDB \u30b5\u30fc\u30d0\u30fc\u3092\u518d\u8d77\u52d5\u3059\u308c\u3070\u30a8\u30e9\u30fc\u304c\u51fa\u306a\u304f\u306a\u308a\u307e\u3059\u3002\u306a\u306e\u3067\u624b\u3063\u53d6\u308a\u65e9\u304f\u89e3\u6c7a\u3059\u308b\u306b\u306f\u3053\u306e\u65b9\u6cd5\u3067\u9003\u3052\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\n<\/p>\n<h3>\u30a8\u30e9\u30fc\u306e\u539f\u56e0<\/h3>\n<p>\n  \u4eca\u56de\u306e\u30b1\u30fc\u30b9\u306f SimpleAuth \u306e\u4e2d\u3067\u3001created_at \u3084 updated_at \u3092 int \u578b\uff08UNIX \u30bf\u30a4\u30e0\u30b9\u30bf\u30f3\u30d7\u3092\u4fdd\u5b58\uff09\u3067\u6c7a\u3081\u6253\u3061\u3057\u3066\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u3067\u3059\u3002\n<\/p>\n<pre><code class=\"php\">\r\n\t$update['updated_at'] = \\Date::forge()->get_timestamp();\r\n<\/code><\/pre>\n<p>\n  Model_Crud \u306e\u5834\u5408\u306f update_at \u306e\u66f4\u65b0\u306e\u305f\u3081\u306b\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b <var>$_mysql_timestamp<\/var> \u306b\u3088\u3063\u3066\u30bb\u30c3\u30c8\u3059\u308b\u5024\u3092\u5909\u3048\u3066\u3044\u307e\u3059\u3002\n<\/p>\n<pre><code class=\"php\">\r\nif(isset(static::$_mysql_timestamp) and static::$_mysql_timestamp === true)\r\n{\r\n    $vars[static::$_updated_at] = \\Date::forge()->format('mysql');\r\n}\r\nelse\r\n{\r\n    $vars[static::$_updated_at] = \\Date::forge()->get_timestamp();\r\n}\r\n<\/code><\/pre>\n<p>\n  SimpleAuth \u3067\u3082\u3001\u540c\u3058\u5bfe\u5fdc\u3092\u3059\u308c\u3070\u89e3\u6c7a\u3057\u305d\u3046\u3067\u3059\u3002\n<\/p>\n<h3>SimpleAuth \u306e\u6539\u826f<\/h3>\n<p>\n  \u5bfe\u5fdc\u65b9\u91dd\u3068\u3057\u3066\u306f\u3001config\/simpleauth.php \u306b <var>table_mysql_timestamp<\/var> \u306e\u3088\u3046\u306a\u8ffd\u52a0\u9805\u76ee\u3092\u8a2d\u3051\uff08\u30c7\u30d5\u30a9\u30eb\u30c8\u306f false\uff09\u3066\u3001Model_Crud \u306e\u3088\u3046\u306b\u51e6\u7406\u3092\u5206\u5c90\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002\n<\/p>\n<p>\n  \u5177\u4f53\u7684\u306b\u306f created_at, updated_at \u304a\u3088\u3073 last_login \u3092\u30bb\u30c3\u30c8\u3059\u308b\u90e8\u5206\u306e\u524d\u306b\n<\/p>\n<pre><code class=\"php\">\r\n\t\tif(\\Config::get('simpleauth.table_mysql_timestamp'))\r\n\t\t{\r\n\t\t\t$update['updated_at'] = \\Date::forge()->format('mysql');\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\t$update['updated_at'] = \\Date::forge()->get_timestamp();\r\n\t\t}\r\n<\/code><\/pre>\n<p>\n  \u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u3092\u5165\u308c\u3066\u3001\u305d\u306e\u5024\u3092\u30af\u30a8\u30ea\u30d3\u30eb\u30c0\u30fc\u3067\u30bb\u30c3\u30c8\u3059\u308b\u3088\u3046\u306b\u305d\u308c\u305e\u308c\u4fee\u6b63\u3057\u307e\u3057\u305f\u3002\n<\/p>\n<p>\n  \u3053\u308c\u3067\u3001 MariaDB \u30b5\u30fc\u30d0\u30fc\u306e sql_mode \u3092\u5143\u901a\u308a <samp>STRICT_TRANS_TABLES<\/samp> \u306b\u623b\u3057\u3066\u3082\u3001\u30a8\u30e9\u30fc\u3092\u51fa\u3055\u306a\u3044\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002\n<\/p>\n<h3>IT\u30a8\u30f3\u30b8\u30cb\u30a2\u52df\u96c6\u4e2d\uff01<\/h3>\n<p>\u30ad\u30e5\u30a2\u30b3\u30fc\u30c9\u682a\u5f0f\u4f1a\u793e\u306fIT\u30a8\u30f3\u30b8\u30cb\u30a2\u3092\u52df\u96c6\u3057\u3066\u304a\u308a\u307e\u3059\u3002\u5c11\u4eba\u6570\u306e\u8077\u5834\u306a\u306e\u3067\u3001\u4e0a\u6d41\u30fb\u4e0b\u6d41\u3084\u30b5\u30fc\u30d0\u30fc\u30fb\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5bfe\u5fdc\u306e\u57a3\u6839\u306a\u304f\u3001\u3042\u306a\u305f\u306e\u5f37\u307f\u3092\u6d3b\u304b\u3057\u306a\u304c\u3089 \u3044\u308d\u3044\u308d\u306a\u3053\u3068\u306b\u30c1\u30e3\u30ec\u30f3\u30b8\u53ef\u80fd\u3067\u3059\u3002\u30a8\u30f3\u30b8\u30cb\u30a2\u3068\u3057\u3066\u306e\u672a\u7d4c\u9a13\u306e\u65b9\u3001\u7d4c\u9a13\u304c\u5c11\u306a\u3044\u65b9\u3082\u6b53\u8fce\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u4e0b\u8a18\u3088\u308aIT\u30a8\u30f3\u30b8\u30cb\u30a2\u52df\u96c6\u306e\u63a1\u7528\u60c5\u5831\u3092\u3054\u89a7\u3044\u305f\u3060\u3051\u307e\u3059\u3002<\/p>\n<div class=\"curecode_recruit_bn\">\n\t\t\t\t<a href=\"https:\/\/curecode.jp\/recruit\/itengineer\/\" target=\"_blank\" rel=\"noopener noreferrer\"><br \/>\n\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/curecode.jp\/tech\/wp-content\/themes\/tech\/images\/it_recruit.png?20241220\" alt=\"\u4e8b\u696d\u62e1\u5927\u306b\u4f34\u3044\u65b0\u3057\u3044\u9818\u57df\u306b\u4e00\u7dd2\u306b\u53d6\u308a\u7d44\u3093\u3067\u3044\u304f\u30e1\u30f3\u30d0\u30fc\u3092\u52df\u96c6\u3057\u307e\u3059\u3002\"  width=\"500\" height=\"180\"\/><br \/>\n\t\t\t\t<\/a>\n\t\t<\/div>\n<h3>\u30ad\u30e5\u30a2\u30b3\u30fc\u30c9\u516c\u5f0f\u30a4\u30f3\u30b9\u30bf\u30b0\u30e9\u30e0<\/h3>\n<p>\u30ad\u30e5\u30a2\u30b3\u30fc\u30c9\u682a\u5f0f\u4f1a\u793e\u306e\u65b0\u30b5\u30fc\u30d3\u30b9\u60c5\u5831\u3084\u3001\u30aa\u30d5\u30a3\u30b9\u30e9\u30a4\u30d5\u306e\u7d20\u6575\u306a\u77ac\u9593\u307e\u3067\u3002\u79c1\u305f\u3061\u306e\u65e5\u3005\u306e\u55b6\u307f\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<div class=\"curecode_recruit_bn\">\n\t\t\t\t<a href=\"https:\/\/www.instagram.com\/curecode\/\" target=\"_blank\" rel=\"noopener noreferrer\"><br \/>\n\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/curecode.jp\/tech\/wp-content\/themes\/tech\/images\/insta_bn.png?20241220\" alt=\"\u4e8b\u696d\u62e1\u5927\u306b\u4f34\u3044\u65b0\u3057\u3044\u9818\u57df\u306b\u4e00\u7dd2\u306b\u53d6\u308a\u7d44\u3093\u3067\u3044\u304f\u30e1\u30f3\u30d0\u30fc\u3092\u52df\u96c6\u3057\u307e\u3059\u3002\"  width=\"500\" height=\"180\"\/><br \/>\n\t\t\t\t<\/a>\n\t\t<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u63d0\u6761\u4ef6 SimpleAuth FuelPHP \u306e Auth \u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u9644\u5c5e\u3057\u3066\u3044\u308b Simple [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":591,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,84],"tags":[39,85,71,124],"class_list":["post-1395","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-fuelphp","category-mysql","tag-fuelphp","tag-mariadb","tag-mysql","tag-simpleauth"],"_links":{"self":[{"href":"https:\/\/curecode.jp\/tech\/wp-json\/wp\/v2\/posts\/1395","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/curecode.jp\/tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/curecode.jp\/tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/curecode.jp\/tech\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/curecode.jp\/tech\/wp-json\/wp\/v2\/comments?post=1395"}],"version-history":[{"count":11,"href":"https:\/\/curecode.jp\/tech\/wp-json\/wp\/v2\/posts\/1395\/revisions"}],"predecessor-version":[{"id":1406,"href":"https:\/\/curecode.jp\/tech\/wp-json\/wp\/v2\/posts\/1395\/revisions\/1406"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/curecode.jp\/tech\/wp-json\/wp\/v2\/media\/591"}],"wp:attachment":[{"href":"https:\/\/curecode.jp\/tech\/wp-json\/wp\/v2\/media?parent=1395"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/curecode.jp\/tech\/wp-json\/wp\/v2\/categories?post=1395"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/curecode.jp\/tech\/wp-json\/wp\/v2\/tags?post=1395"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}