Last active
November 14, 2016 05:32
-
-
Save taitokiss/9b8d13af49b64aa317178b871f223baa to your computer and use it in GitHub Desktop.
mysql_系 データベースへの接続サンプル(手続き型)
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 = mysql_connect("localhost", "testuser", "testuser"); | |
if (!$link) { | |
die("接続失敗" . mysql_error()); | |
} | |
// データベースの選択 | |
$db = mysql_select_db("uriage"); | |
if (!$db){ | |
die("データベースの選択失敗" . mysql_error()); | |
} | |
// 文字化け防止 | |
mysql_set_charset("utf8"); | |
// SELECT文の発行 | |
$result = mysql_query("SELECT id, name FROM shouhin"); | |
if (!$result) { | |
die("クエリーが失敗" . mysql_error()); | |
} | |
// データの取得及び取得データの表示 | |
while ($row = mysql_fetch_assoc($result)) { | |
echo "id=" . $row["id"]; | |
echo ",name=" . $row["name"] . "<br />"; | |
} | |
// MySQLの切断 | |
$close = mysql_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