Created
January 24, 2012 14:33
-
-
Save yandod/1670456 to your computer and use it in GitHub Desktop.
PDOとmod_rewriteの動作状況確認スクリプト (CakePHP2にはPDOが必要です。mod_rewriteはあった方が良い。)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
SET NAMES utf8 を足すのもアリですー。
動きました!!
今日はよろしくお願いします!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PHP5.3.6で動きました〜。準備おつかれさまです!
PHP5.2.xだと、charset指定が効かず文字化けしそう。
$dbh->query("SET NAMES utf8");
とかしとけばOKですか?