コメント |
[[CP932]]
@DIV
<?php
header( "Content-Type: text/html; Charset=shift_jis" );
header( "pragma: no-cache" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );
header( "Cache-control: no-cache" );
$server = 'localhost';
$db_name = 'データベース名';
$user = 'root';
$password = 'パスワード';
$connect_string = "Provider=MSDASQL;";
$connect_string .= "Driver={MySQL ODBC 5.3 Unicode Driver};";
$connect_string .= "Server={$server};";
$connect_string .= "DATABASE={$db_name};";
$connect_string .= "UID={$user};";
$connect_string .= "PWD={$password};";
$connect_string .= "charset=cp932;";
// このキャラクタ設定は、サーバーからのキャラクタセット
// クライアントは SHIFT_JIS が前提で、インストールされた PCに依存しているようです。
// 接続
$connect = @odbc_connect($connect_string, "", "");
if ( !$connect ) {
die("接続エラーです : " . odbc_errormsg() );
}
// クエリ
$result = @odbc_exec($connect,"select * from 社員マスタ");
if ( !$result ) {
die('クエリーに誤りがあります : ' . odbc_errormsg() );
}
// 列数
$field_count = odbc_num_fields( $result );
$count = 0;
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="shift_jis">
<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
print $connect_string;
print "<table>\n";
while (odbc_fetch_into($result,$row)) {
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++;
}
print "</table>";
// メモリ開放
odbc_free_result($result);
// 接続解除
odbc_close($connect);
?>
<br>
出力件数 : <?= $count ?>
@END
[[UTF-8]]
@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" );
mb_language( "ja" );
mb_internal_encoding("utf-8");
$server = 'localhost';
$db_name = 'データベース名';
$user = 'root';
$password = 'パスワード';
$connect_string = "Provider=MSDASQL;";
$connect_string .= "Driver={MySQL ODBC 5.3 Unicode Driver};";
$connect_string .= "Server={$server};";
$connect_string .= "DATABASE={$db_name};";
$connect_string .= "UID={$user};";
$connect_string .= "PWD={$password};";
$connect_string .= "charset=utf8;";
// このキャラクタ設定は、サーバーからのキャラクタセット
// クライアントは SHIFT_JIS が前提で、インストールされた PCに依存しているようです。
// 接続
$connect = @odbc_connect($connect_string, "", "");
if ( !$connect ) {
die("接続エラーです : " . odbc_errormsg() );
}
// クエリ
$query = mb_convert_encoding( "select * from 社員マスタ", "cp932", "utf-8" );
$result = @odbc_exec($connect, $query );
if ( !$result ) {
die('クエリーに誤りがあります : ' . odbc_errormsg() );
}
// 列数
$field_count = odbc_num_fields( $result );
$count = 0;
?>
<!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
print $connect_string;
print "<table>\n";
while (odbc_fetch_into($result,$row)) {
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++;
}
print "</table>";
// メモリを開放
odbc_free_result($result);
// 接続解除
odbc_close($connect);
?>
<br>
出力件数 : <?= $count ?>
@END
|