<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=x-euc-jp">
<title>MySQLテスト</title>
</head>
<body>
<?php
// 接続先DBの情報の設定
$DB = array(
// 接続先サーバ
'host' => "localhost",
// mysqlアカウント名
'user' => "bj0000",
// mysqlパスワード
'pass' => "password",
// データベース名(アカウント名と同一)
'name' => "bj0000",
);
// MySQL サーバに接続
$link = mysql_connect($DB[host], $DB[user], $DB[pass]);
// データベースの選択
mysql_select_db($DB[name], $link);
// テーブル "NINJIN" の作成
$com_create_table = "create table if not exists NINJIN (
id int(5) ZEROFILL AUTO_INCREMENT,
name char(100),
mail char(100),
PRIMARY KEY(id)
)";
mysql_query($com_create_table, $link);
print mysql_error();
// テーブル "NINJIN" にレコードを登録
$com_insert = "insert into NINJIN values(null, \"big-server\", \"server@maido3.com\")";
mysql_query($com_insert, $link);
print mysql_error();
// テーブル "NINJIN" 内データの表示
$com_select = "select * from NINJIN";
$result = mysql_query($com_select, $link);
while( $Item = mysql_fetch_assoc($result) ) {
foreach( $Item as $key => $value ) {
print "key : $key => value : $value<br>\n";
}
print "<br>\n";
}
// 接続のclose
mysql_close($link);
?>
<body>
</html> |