コメント |
@DIV
<?php
header( "Content-Type: text/html; Charset=utf-8" );
header( "pragma: no-cache" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );
header( "Cache-control: no-cache" );
$host = 'localhost';
$db_name = 'dbtest';
$user = 'root';
$password = 'パスワード';
// 接続
$connect = @mysql_connect( $host, $user, $password );
if ( !$connect ) {
die("接続エラーです : " . mysql_error() );
}
// DB選択
if ( !mysql_select_db( $db_name, $connect ) ) {
die("DB選択に誤りがあります : " . mysql_error() );
}
// -----------------------------------------------
// ▼ ビュー
// -----------------------------------------------
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<style>
* {
font-family: "メイリオ", Meiryo, "MS Pゴシック", sans-serif;
font-size: 12px;
}
table {
border-collapse: collapse;
border: solid 1px #c0c0c0;
background-color: #ffffff;
}
td {
padding: 5px;
border: solid 1px #c0c0c0;
}
</style>
</head>
<body>
<?php
// クエリ
$result = mysql_query("select * from 社員マスタ", $connect);
if ( !$result ) {
die('クエリーに誤りがあります : ' . mysql_error());
}
// 列数
$field_count = mysql_num_fields( $result );
// 出力件数用
$count = 0;
// 内容を書き込むファイルの準備
$log_file = "rowdata_001.log";
file_put_contents( $log_file,"" );
print "<table>\n";
while ($row = mysql_fetch_array($result)) {
print "<tr>\n";
print "\t<td>" . ($count + 1) . "</td>\n"; // 行番号
for( $i = 0; $i < $field_count; $i++ ) {
print "\t<td>{$row[$i]}</td>\n";
}
print "</tr>\n";
$count++;
// ファイルに追加出力
file_put_contents( $log_file, print_r($row,true), FILE_APPEND );
}
print "</table>";
// メモリを開放ですが、PHP が終了するので必要ありません
mysql_free_result($result);
// 接続解除
mysql_close($connect);
?>
<br>
出力件数 : <?= $count ?>
@END |