Skip to content

Instantly share code, notes, and snippets.

@yandod
Created January 24, 2012 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yandod/1670456 to your computer and use it in GitHub Desktop.
Save yandod/1670456 to your computer and use it in GitHub Desktop.
PDOとmod_rewriteの動作状況確認スクリプト (CakePHP2にはPDOが必要です。mod_rewriteはあった方が良い。)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<?php
//DBの接続情報
$user = 'root';
$pass = 'pass';
$name = 'yourdatabase';
/**
-- 下記のデータをmysqlの任意のデータベースに登録してください。
CREATE TABLE IF NOT EXISTS `FOO` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`number` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=3 ;
INSERT INTO `FOO` (`id`, `name`, `number`) VALUES
(1, '下北沢', 10),
(2, '渋谷', 20);
**/
$dbh = new PDO(
'mysql:host=localhost;dbname='.$name.';charset=utf8',
$user,
$pass
);
echo '<pre>';
foreach($dbh->query('SELECT * from FOO') as $row) {
print_r($row);
}
if (function_exists('apache_get_modules')) {
echo "apache modules\r\n";
print_r(apache_get_modules());
} else {
echo 'not apache';
}
?>
</body>
</html>
@yandod
Copy link
Author

yandod commented Jan 24, 2012

うまく動作すれば下記のようになります。
https://skitch.com/yando/g5mxp/127.0.0.1-8080-testdir-pdosample.php

@cognitom
Copy link

PHP5.3.6で動きました〜。準備おつかれさまです!
PHP5.2.xだと、charset指定が効かず文字化けしそう。
$dbh->query("SET NAMES utf8");
とかしとけばOKですか?

@yandod
Copy link
Author

yandod commented Jan 24, 2012

SET NAMES utf8 を足すのもアリですー。

@ShinichiNishikawa
Copy link

動きました!!

今日はよろしくお願いします!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment