フロントエンドの学習を頑張る2
前回(フロントエンドの学習を頑張る1)に引き続き頑張る。
ライセンス購入しちゃったことだしMySQLクライアントは TablePlus でやる。前回までは post できてるっぽいけどデータが入らないなーうーん、というところで終わった。カラム設定の見直しとコピペでよくミスる`(逆クオート)
や;
なんかがおかしくなってないか一行一行よく見る。よく見る。よく見る。。。よく見た感じ別におかしいところは無さげ。
カラム設定の AUTO_INCREMENT を column_default と extra のどっちに?はデフォルトはなんか違うっぽいので extra に設定しておく。Primary もどこで設定するのかわからなかったが Name の横にタグっぽく表示されているのがそれっぽい。
そもそもSQLサーバー起動してんの?とかSQLコマンド打ってみてデータ入るのか試してみる。
まずMySQLにログインしてーの
$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 8.0.17 Homebrew Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
操作するDBをUSEで選択する必要があるらしい。
mysql> USE bulletin_board Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed
そこにDBはあるんか?
mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | bulletin_board | +--------------------+ 5 rows in set (0.00 sec)
ある。
そこにテーブルはあるんか?
mysql> SHOW TABLES; +--------------------------+ | Tables_in_bulletin_board | +--------------------------+ | boards | | messages | +--------------------------+ 2 rows in set (0.00 sec)
ある。
そこに INSERT できるんか?
mysql> INSERT INTO boards (title, created_at) VALUE ('初めてのNode.js','2019-10-10 00:00:00'); Query OK, 1 row affected (0.01 sec)
できうr... SQLコマンドで直接INSERTできましたれば、じゃあやっぱコードのどこかがおかしいのか。どこだ。どこなの貞子。 怪しいのはやはりこの辺な気がするのだけど、
var query = 'INSERT INTO boards (title, created_at) VALUES ("' + title + '", ' + '"' + createdAt + '")';
最後に;
が足りないせいなんじゃないのとか。値が入ってないんじゃないのとか。違った。超違ったよ。
mysqlConnection.js にパスワード入れてなかった。そういえば root のパスワード設定したんだった。いやー。
できたわ。