ソース掲示板




すべてから検索

キーワード   条件 表示 現行ログ 過去ログ トピックス 名前 本文

  メンテナンス 前画面に戻る

対象スレッド 件名: DB と連携
名前: lightbox
処理選択
パスワード

件名 DB と連携
名前 lightbox
コメント
http://lightbox.on.coocan.jp/image/jpgraph18_2.png

ローカルでテストしているので、表示とDB のキャラクタセットが一致していないので
$conf_db_charset をセットしています。
DB から読み出されたデータは、自動的に変換されます。
( MySQL 4.1 以上の場合は $conf_db_connect_action = "set names 'ujis'"; でもかまいません )

http://lightbox.matrix.jp/ginpro/patio.cgi?mode=view&no=146&w=710&type=ref&opt=text-align:left;margin-left:50px&xml=y(PHP 用 リモート db クラス利用方法)

@DIV
<?

$conf_client_charset = "euc-jp";
$conf_common_path1 = "http://lightbox.in.coocan.jp/gensjis/";
$conf_common_path2 = "http://lightbox.in.coocan.jp/gen/";

$conf_db_type = 1;
$conf_db_host = "localhost";
$conf_db_db = "lightbox";
$conf_db_user = "root"; 
$conf_db_pass = ""; 
$conf_db_charset = 'SHIFT_JIS';

?>
@END

@DIV
<?
set_include_path( "/user/php/jpgraph-1.21b/src" );
# **********************************************************
# 外部ファイル
# **********************************************************
require_once( "conf.php" );
require_once( "{$conf_common_path1}common.txt" );
require_once( "{$conf_common_path2}db.txt" );
include ("jpgraph.php");
include ("jpgraph_bar.php");

# **********************************************************
# 接続
# **********************************************************
$SQL = new DB( "localhost", "lightbox", "root", ""  );

$Query = "select * from 社員マスタ";
$Query .= " where 社員コード <= '0010'";
$Query .= " order by 社員コード";
$Column = $SQL->QueryEx( $Query );
$first = $Column['氏名'];
$datay = array();
while( $Column ) {

	$datay[] = floor( $Column['給与'] / 10000 );
	$Column = $SQL->QueryEx( );
}

# **********************************************************
# 接続解除
# **********************************************************
$SQL->Close();

// Create the graph. These two calls are always required
$graph = new Graph(600,300,"auto");	
$graph->SetScale("textlin");

// Add a drop shadow
$graph->SetShadow();

// Adjust the margin a bit to make more room for titles
$graph->img->SetMargin(40,30,20,40);

// Create a bar pot
$bplot = new BarPlot($datay);
$graph->Add($bplot);

// Setup the titles

// 内部コード設定
mb_language( "ja" );
mb_internal_encoding("EUC-JP");

// UTF-8 に変換
$str = $first;
$str = mb_convert_encoding ( $str, "UTF-8" );

$graph->title->Set( $str );
$graph->xaxis->title->Set( mb_convert_encoding ( "x 座標", "UTF-8" ) );
$graph->yaxis->title->Set( mb_convert_encoding ( "y 座標", "UTF-8" ) );

// フリーフォントの指定
$graph->title->SetFont(FF_GOTHIC);
$graph->yaxis->title->SetFont(FF_GOTHIC);
$graph->xaxis->title->SetFont(FF_GOTHIC);

// Display the graph
$graph->Stroke();
?>
@END