Last active
November 14, 2016 05:30
-
-
Save taitokiss/460aad0c2f4e9e825956be9ce9bc4030 to your computer and use it in GitHub Desktop.
mysqli_系 データベースへの接続サンプル2(手続き型)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// MySQLへ接続及びデータベースの選択 | |
$link = mysqli_connect("localhost", "testuser", "testuser", "uriage"); | |
if(mysqli_connect_errno() > 0){ | |
die("接続失敗" . mysqli_connect_error()); | |
} | |
// 文字化け防止 | |
mysqli_set_charset($link, "utf8"); | |
// SELECT文の発行 | |
$result = mysqli_query($link, "SELECT id, name FROM shouhin"); | |
if (!$result) { | |
die("クエリーが失敗" . mysqli_error()); | |
} | |
// データの取得及び取得データの表示 | |
while ($row = mysqli_fetch_assoc($result)) { | |
echo "id=" . $row["id"]; | |
echo ",name=" . $row["name"] . "<br />"; | |
} | |
// MySQLの切断 | |
$close = mysqli_close($link); | |
if ($close){ | |
echo "<p>切断成功</p>"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment