SQLの窓 イラストAC フリー素材

2014年07月18日

【PHP】WEB上にあるライブラリを使って簡単にMySQLにアクセス

キャラクタセットの設定について

クライアントが、EUC-JP の場合は、mysql_set_charset("eucjpms", $SQL->Connect) を実行し、クライアントが SHIFT_JIS の場合は、mysql_set_charset("cp932", $SQL->Connect) を実行します
<?php
header( "Content-Type: text/html; Charset=utf-8" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );

require_once( "http://homepage2.nifty.com/lightbox/gen/db.php");
$conf_db_type = 1;
$SQL = new DB( "サーバー","DB","ユーザー","パスワード" );
$SQL->Debug = true;
mysql_set_charset("utf8", $SQL->Connect);

$Query = "select * from `社員マスタ`";
$Column = $SQL->QueryEx( $Query );

print "<pre>";
while( $Column ) {

	print "<HR>";
	print_r($Column);

	$Column = $SQL->QueryEx( );

}
print "</pre>";

$SQL->Close();
?>



allow_url_include が Off になっている場合
<?php
header( "Content-Type: text/html; Charset=utf-8" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );

function inc( $path ) {

	$inc = @file( $path );
	array_shift($inc);
	array_pop($inc);
	$GLOBALS['inc_eval_txt'] = implode( "", $inc );
	eval($GLOBALS['inc_eval_txt']);
}
inc( "http://homepage2.nifty.com/lightbox/gen/db.php");
$conf_db_type = 1;
$SQL = new DB( "サーバー","DB","ユーザー","パスワード" );
$SQL->Debug = true;

$Query = "select * from `社員マスタ`";
$Column = $SQL->QueryEx( $Query );

print "<pre>";
while( $Column ) {

	print "<HR>";
	print_r($Column);

	$Column = $SQL->QueryEx( );

}
print "</pre>";

$SQL->Close();
?>

※ utf-8n で記述 / DBも utf-8

▼ オンライン簡易DBクラス
http://homepage2.nifty.com/lightbox/gen/db.php



posted by at 2014-07-18 01:10 | PHP+DB | このブログの読者になる | 更新情報をチェックする