Skip to content

Instantly share code, notes, and snippets.

@taitokiss
Last active November 14, 2016 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taitokiss/9b8d13af49b64aa317178b871f223baa to your computer and use it in GitHub Desktop.
Save taitokiss/9b8d13af49b64aa317178b871f223baa to your computer and use it in GitHub Desktop.
mysql_系 データベースへの接続サンプル(手続き型)
<?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