Skip to content

Instantly share code, notes, and snippets.

@taitokiss
Last active November 14, 2016 05:30
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/460aad0c2f4e9e825956be9ce9bc4030 to your computer and use it in GitHub Desktop.
Save taitokiss/460aad0c2f4e9e825956be9ce9bc4030 to your computer and use it in GitHub Desktop.
mysqli_系 データベースへの接続サンプル2(手続き型)
<?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