ソース掲示板




すべてから検索

キーワード   条件 表示 現行ログ 過去ログ トピックス 名前 本文
PHP + MySQL
日時: 2015/09/07 16:52
名前: lightbox



▼ phpMyAdmin の最も簡単なセットアップ
http://matome.naver.jp/odai/2144153548249001301

社員マスタ.sql
拡張子:
-- phpMyAdmin SQL Dump
-- version 4.4.14
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: 2015 年 9 月 07 日 16:38
-- サーバのバージョン: 5.6.17
-- PHP Version: 5.4.13

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `dbtest`
--

-- --------------------------------------------------------

--
-- テーブルの構造 `社員マスタ`
--

CREATE TABLE IF NOT EXISTS `社員マスタ` (
  `社員コード` varchar(4) NOT NULL DEFAULT '',
  `氏名` varchar(50) DEFAULT NULL,
  `フリガナ` varchar(50) DEFAULT NULL,
  `所属` varchar(4) DEFAULT NULL,
  `性別` int(11) DEFAULT NULL,
  `作成日` datetime DEFAULT NULL,
  `更新日` datetime DEFAULT NULL,
  `給与` int(11) DEFAULT NULL,
  `手当` int(11) DEFAULT NULL,
  `管理者` varchar(4) DEFAULT NULL
);

--
-- テーブルのデータのダンプ `社員マスタ`
--

INSERT INTO `社員マスタ` (`社員コード`, `氏名`, `フリガナ`, `所属`, `性別`, `作成日`, `更新日`, `給与`, `手当`, `管理者`) VALUES
('0001', '浦岡 友也', 'ウラオカ トモヤ', '0003', 0, '2005-09-12 00:00:00', '2005-11-28 00:00:00', 270000, 9000, NULL),
('0002', '山村 洋代', 'ヤマムラ ヒロヨ', '0003', 1, '2005-06-17 00:00:00', '2005-09-18 00:00:00', 300000, NULL, NULL),
('0003', '多岡 冬行', 'タオカ フユユキ', '0002', 0, '2005-08-14 00:00:00', '2005-11-14 00:00:00', 250000, NULL, NULL),
('0004', '高田 冬美', 'タカタ フユミ', '0003', 1, '2005-06-13 00:00:00', '2005-10-05 00:00:00', 250000, NULL, NULL),
('0005', '内高 友之', 'ウチタカ トモユキ', '0003', 0, '2005-09-12 00:00:00', '2005-11-10 00:00:00', 150000, NULL, NULL),
('0006', '森尾 正也', 'モリオ マサヤ', '0002', 0, '2005-08-14 00:00:00', '2005-12-17 00:00:00', 300000, 7000, '0002'),
('0007', '鈴杉 由樹', 'スズスギ ヨシキ', '0001', 0, '2005-07-12 00:00:00', '2005-10-03 00:00:00', 170000, NULL, '0003'),
('0008', '川吉 洋樹', 'カワヨシ ヒロキ', '0002', 0, '2005-08-15 00:00:00', '2005-12-14 00:00:00', 240000, NULL, '0004'),
('0009', '村森 友恵', 'ムラモリ トモエ', '0003', 1, '2005-09-11 00:00:00', '2005-11-06 00:00:00', 290000, NULL, '0003'),
('0010', '杉岡 友一', 'スギオカ トモカズ', '0002', 0, '2005-08-17 00:00:00', '2005-09-18 00:00:00', 180000, NULL, '0005'),
('0011', '川多 由男', 'カワタ ヨシオ', '0002', 0, '2005-08-19 00:00:00', '2005-11-15 00:00:00', 230000, 5000, '0005'),
('0012', '杉岡 由樹', 'スギオカ ヨシキ', '0002', 0, '2005-06-29 00:00:00', '2005-11-12 00:00:00', 280000, NULL, '0001'),
('0013', '木川 元男', 'キカワ モトオ', '0001', 0, '2005-07-21 00:00:00', '2005-11-18 00:00:00', 230000, NULL, '0005'),
('0014', '川木 春一', 'カワキ ハルカズ', '0001', 0, '2005-07-04 00:00:00', '2005-12-15 00:00:00', 230000, NULL, '0001'),
('0015', '中多 克也', 'ナカタ カツヤ', '0001', 0, '2005-09-04 00:00:00', '2005-11-11 00:00:00', 160000, NULL, '0005'),
('0016', '森村 正恵', 'モリムラ マサエ', '0001', 1, '2005-07-07 00:00:00', '2005-10-08 00:00:00', 150000, 5000, '0002'),
('0017', '尾田 雅也', 'オタ マサヤ', '0002', 0, '2005-09-09 00:00:00', '2005-10-31 00:00:00', 170000, NULL, '0005'),
('0018', '松中 輝行', 'マツナカ テルユキ', '0001', 0, '2005-07-11 00:00:00', '2005-10-24 00:00:00', 300000, NULL, '0001'),
('0019', '野丸 由一', 'ノマル ヨシカズ', '0001', 0, '2005-06-05 00:00:00', '2005-09-26 00:00:00', 140000, NULL, '0002'),
('0020', '松野 友之', 'マツノ トモユキ', '0003', 0, '2005-07-08 00:00:00', '2005-11-24 00:00:00', 300000, NULL, '0002'),
('0021', '吉村 春一', 'ヨシムラ ハルカズ', '0002', 0, '2005-06-23 00:00:00', '2005-11-06 00:00:00', 210000, 8000, '0002'),
('0022', '丸吉 春代', 'マルヨシ ハルヨ', '0001', 1, '2005-08-15 00:00:00', '2005-09-28 00:00:00', 230000, NULL, '0002'),
('0023', '松本 洋也', 'マツモト ヒロヤ', '0003', 0, '2005-06-30 00:00:00', '2005-11-14 00:00:00', 270000, NULL, '0001'),
('0024', '尾木 輝男', 'オキ テルオ', '0003', 0, '2005-08-06 00:00:00', '2005-10-29 00:00:00', 160000, NULL, '0001'),
('0025', '鈴川 春美', 'スズカワ ハルミ', '0001', 1, '2005-07-28 00:00:00', '2005-11-27 00:00:00', 260000, NULL, '0002'),
('0026', '原中 元美', 'ハラナカ モトミ', '0001', 1, '2005-08-01 00:00:00', '2005-10-23 00:00:00', 180000, 10000, '0005'),
('0027', '浦村 春一', 'ウラムラ ハルカズ', '0002', 0, '2005-06-10 00:00:00', '2005-09-25 00:00:00', 240000, NULL, '0002'),
('0028', '森木 和之', 'モリキ カズユキ', '0002', 0, '2005-07-26 00:00:00', '2005-12-20 00:00:00', 170000, NULL, '0002'),
('0029', '多田 友行', 'タタ トモユキ', '0003', 0, '2005-07-19 00:00:00', '2005-12-13 00:00:00', 250000, NULL, '0003'),
('0030', '浦川 冬代', 'ウラカワ フユヨ', '0001', 1, '2005-08-22 00:00:00', '2005-10-15 00:00:00', 270000, NULL, '0001'),
('0031', '岡中 冬之', 'オカナカ フユユキ', '0003', 0, '2005-07-07 00:00:00', '2005-12-13 00:00:00', 280000, 7000, '0001'),
('0032', '野尾 春男', 'ノオ ハルオ', '0001', 0, '2005-08-28 00:00:00', '2005-11-03 00:00:00', 200000, NULL, '0001'),
('0033', '田杉 洋也', 'タスギ ヒロヤ', '0003', 0, '2005-08-07 00:00:00', '2005-10-15 00:00:00', 270000, NULL, '0002'),
('0034', '村高 洋代', 'ムラタカ ヒロヨ', '0002', 1, '2005-06-19 00:00:00', '2005-11-11 00:00:00', 290000, NULL, '0003'),
('0035', '本原 正也', 'モトハラ マサヤ', '0002', 0, '2005-09-13 00:00:00', '2005-11-26 00:00:00', 280000, NULL, '0002'),
('0036', '浦多 冬代', 'ウラタ フユヨ', '0001', 1, '2005-08-03 00:00:00', '2005-10-17 00:00:00', 260000, 6000, '0004'),
('0037', '鈴丸 輝之', 'スズマル テルユキ', '0001', 0, '2005-06-06 00:00:00', '2005-11-15 00:00:00', 240000, NULL, '0005'),
('0038', '松高 洋一', 'マツタカ ヒロカズ', '0003', 0, '2005-08-20 00:00:00', '2005-10-21 00:00:00', 200000, NULL, '0003'),
('0039', '高松 雅之', 'タカマツ マサユキ', '0001', 0, '2005-07-10 00:00:00', '2005-12-12 00:00:00', 170000, NULL, '0005'),
('0040', '安村 克恵', 'ヤスムラ カツエ', '0002', 1, '2005-08-25 00:00:00', '2005-10-15 00:00:00', 210000, NULL, '0001'),
('0041', '丸森 雅美', 'マルモリ マサミ', '0001', 1, '2005-06-05 00:00:00', '2005-10-30 00:00:00', 140000, 7000, '0002'),
('0042', '中原 冬男', 'ナカハラ フユオ', '0001', 0, '2005-08-29 00:00:00', '2005-10-21 00:00:00', 170000, NULL, '0005'),
('0043', '原松 春也', 'ハラマツ ハルヤ', '0001', 0, '2005-06-22 00:00:00', '2005-12-01 00:00:00', 270000, NULL, '0002'),
('0044', '村松 冬子', 'ムラマツ フユコ', '0001', 1, '2005-08-08 00:00:00', '2005-11-09 00:00:00', 190000, NULL, '0003'),
('0045', '村松 和子', 'ムラマツ カズコ', '0003', 1, '2005-06-11 00:00:00', '2005-12-22 00:00:00', 280000, NULL, '0003'),
('0046', '尾内 正樹', 'オウチ マサキ', '0001', 0, '2005-08-10 00:00:00', '2005-11-21 00:00:00', 150000, 5000, '0002'),
('0047', '多松 正樹', 'タマツ マサキ', '0001', 0, '2005-08-07 00:00:00', '2005-10-23 00:00:00', 280000, NULL, '0003'),
('0048', '浦杉 由美', 'ウラスギ ヨシミ', '0002', 1, '2005-08-22 00:00:00', '2005-11-10 00:00:00', 260000, NULL, '0003'),
('0049', '原田 春代', 'ハラタ ハルヨ', '0002', 1, '2005-09-12 00:00:00', '2005-10-12 00:00:00', 300000, NULL, '0004'),
('0050', '松丸 正恵', 'マツマル マサエ', '0003', 1, '2005-09-04 00:00:00', '2005-11-06 00:00:00', 210000, NULL, '0001');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `社員マスタ`
--
ALTER TABLE `社員マスタ`
  ADD PRIMARY KEY (`社員コード`);

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
メンテナンス

旧式 MySQL 関数 ( No.1 )
日時: 2015/09/07 16:55
名前: lightbox


日時: 2015/09/07 16:55
名前: lightbox
拡張子:
<?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 ?>
このアーティクルの参照用URLをクリップボードにコピー メンテナンス
mysqli ( No.2 )
日時: 2015/09/15 21:35
名前: lightbox
UTF-8
拡張子:
<?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" );

$server = 'localhost';
$db_name = 'データベース名';
$user = 'root';
$password = 'パスワード';

// 接続
$connect = @ new mysqli($server, $user, $password, $db_name);
if ($connect->connect_error) {
	die('Connect Error (' . $connect->connect_errno . ') '
	. $connect->connect_error);
}
$connect->set_charset("utf8"); 

// -----------------------------------------------
// ▼ ビュー
// -----------------------------------------------
?>
<!DOCTYPE html>
<html>
<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 = $connect->query("select * from 社員マスタ"); 
if ( !$result ) {
	die('クエリーに誤りがあります : ' . $connect->error );
}

// 列数
$field_count = $connect->field_count;
// 出力件数用
$count = 0;

// 内容を書き込むファイルの準備
$log_file = "rowdata_002.log";
file_put_contents( $log_file,"" );

print "<table>\n";
while ($row = $result->fetch_array(MYSQLI_BOTH)) {

	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>";

// 開放
$result->close();
// 接続解除
$connect->close();

?>

<br>
出力件数 : <?= $count ?>
CP932
拡張子:
<?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 = @ new mysqli($server, $user, $password, $db_name);
if ($connect->connect_error) {
	die('Connect Error (' . $connect->connect_errno . ') '
	. $connect->connect_error);
}
$connect->set_charset("cp932"); 

// -----------------------------------------------
// ▼ ビュー
// -----------------------------------------------
?>
<!DOCTYPE html>
<html>
<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

// クエリ
$result = $connect->query("select * from 社員マスタ"); 
if ( !$result ) {
	die('クエリーに誤りがあります : ' . $connect->error );
}

// 列数
$field_count = $connect->field_count;
// 出力件数用
$count = 0;

// 内容を書き込むファイルの準備
$log_file = "rowdata_002.log";
file_put_contents( $log_file,"" );

print "<table>\n";
while ($row = $result->fetch_array(MYSQLI_BOTH)) {

	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>";

// 開放
$result->close();
// 接続解除
$connect->close();

?>

<br>
出力件数 : <?= $count ?>
このアーティクルの参照用URLをクリップボードにコピー メンテナンス
ODBC ( No.3 )
日時: 2015/09/15 21:38
名前: lightbox
CP932
拡張子:
<?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 ?>
UTF-8
拡張子:
<?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 ?>
このアーティクルの参照用URLをクリップボードにコピー メンテナンス