PHPで接続方法

※接続には4つのデータが必要(データベースホスト名、データベースユーザー名、データベースパスワード、データベース名)

$dbc = mysqli_connect(‘localhost‘,’root‘,’root‘,’ssss_xxxxx‘)or die(‘エラー:MYSQLサーバーとの接続に失敗しました’);

※文字化け回避

mysqli_set_charset($dbc,”utf8″);

赤テーブル名

青カラム

$query = “INSERT INTO xxx_xxxx(last_name,first_name,when_it_happened,how_long,”.how_many,a_description,what_they_did,fang_spotted,other,email)”. “VALUES(‘$last_name’,’$first_name’,’$when_it_happened’,’$how_long’,’$how_many’,’$a_description’,”.”‘$what_they_did’,’$fang_spotted’,’$other’,”.

“‘$email’)”;

※MYsqlサーバーとの接続を閉じる

$result = mysqli_query($dbc,$query)or die(‘エラー:データベースとの問い合わせに失敗しました’);

mysqli_close($dbc);

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です