PHPのWEBサイトで名前、年齢を登録ボタンを押すとMYSQLのテーブルに格納させる設定方法を教えて下さい。(レンタルサーバで各ソフトはインストールしています。)
PHPとMYSQLを連携させる方法
ネットでMYSQLと調べ手順通り作業しました。
設計 http://www.go-next.co.jp/blog/web/php/15962/
登録 http://www.go-next.co.jp/blog/web/php/20735/
MYSQLでSQL文を使用してデータの追加、削除はできます。
<?php define('DB_DATABASE', 'dotinstall_db'); define('DB_USERNAME', 'dbuser'); define('DB_PASSWORD', 'g6fd7Xx'); define('PDO_DSN', 'mysql:dbhost=localhost;dbname=' . DB_DATABASE); try { // connect $db = new PDO(PDO_DSN, DB_USERNAME, DB_PASSWORD); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // update $stmt = $db->prepare("update users set score = :score where name = :name"); $stmt->execute([ ':score' => 100, ':name' => 'taguchi' ]); echo 'row updated: ' . $stmt->rowCount(); // delete $stmt = $db->prepare("delete from users where name = :name"); $stmt->execute([ ':name' => 'dotinstall' ]); echo 'row deleted: ' . $stmt->rowCount(); } catch (PDOException $e) { echo $e->getMessage(); exit; } 下記のPHP.TXTで調べた内容を追記しときます。 問)HTMLとPHPを使い登録ボタンを作成し編集・削除を行いMYSQLのテーブルに格納したいです・ (HTMLで下記の表は作成できます。) 以上、拙いですが、宜しくお願い致します。回答1件
あなたの回答
tips
プレビュー