ããã±ãŒãžãã€ã³ã¹ããŒã«ããæ¹æ³ïŒèªåã§é©åãªä¿®æ£ãå ¥åããŠãã ããïŒïŒ
- Firebird 2.5 x64ããŒãžã§ã³ ïŒãµãŒããŒã®çš®é¡ã¯é¢ä¿ãããŸããïŒ CïŒ\ Program Files \ Firebird \ Firebird_2_5 \
- XAMMPã¯Dã«ã€ã³ã¹ããŒã«ãããŸãïŒ\ xampp \
- YII2ã¯Dã«ã€ã³ã¹ããŒã«ãããŸãïŒ\ xampp \ htdocs \ yii \
- ããŒã¿ããŒã¹ã¯ãã¹Dã«ãããŸãïŒ\ WORK \ database \ TBOT.GDB
ããã§éå§ã§ããŸãã
Firebird Support for PHPãã€ã³ã¹ããŒã«ããŸã
FirebirdãµããŒããã€ã³ã¹ããŒã«ããã«ã¯ãXAMMPã§ApacheãµãŒããŒãåæ¢ããå¿ èŠããããŸãã ãããè¡ãã«ã¯ãXAMMPã³ã³ãœãŒã«ãéããã¹ã¿ãŒããã¿ã³ãApacheãµãŒãã¹ã®å察åŽã«ããããšã確èªããŸãã ãµãŒãã¹ãå®è¡ãããŠããªãå Žåã¯ããåæ¢ããã¯ãªãã¯ããŠãã ããã
æ§æãã¡ã€ã«PHP DïŒ\ xampp \ php \ php.iniããšãã£ã¿ãŒã§éãããã®äžã®è¡ãèŠã€ããŸãã
;extension=php_pdo_firebird.dll
ã;ããåé€ããŸã æåã« ã³ã¡ã³ããå€ããŠä¿åããŸãã DBMSã«ã¢ã¯ã»ã¹ããããã«YII2ã䜿çšããPDOãã©ã€ããŒãæå¹ã«ãªã£ãŠããŸãã ãã ããæ©èœããŸãããæšæºã®ããŒã¿ããŒã¹ã¢ã¯ã»ã¹ã©ã€ãã©ãªfbclient.dllãã³ããŒããå¿ èŠããããŸãã ããã§ã¯æ³šæããå¿ èŠããããŸã Windows x64ããã³Firebird x64ãµãŒããŒãã€ã³ã¹ããŒã«ããŸãããXAMMPã¯32ãããã¢ããªã±ãŒã·ã§ã³ã§ãã ãããã£ãŠã fbclient.dllã©ã€ãã©ãªã¯ãããŒã¿ããŒã¹ãžã®ã¢ã¯ã»ã¹ã«äœ¿çšãããã¯ã©ã€ã¢ã³ãïŒãã®å Žåã¯XAMMPããŸãã¯XAMMPã®äžéšãšããŠã®PHPïŒã®ããŒãžã§ã³çšã«ã³ã³ãã€ã«ããå¿ èŠããããŸãã ã©ã€ãã©ãªã®32ãããããŒãžã§ã³ã¯ãFirebirdã€ã³ã¹ããŒã«ãã£ã¬ã¯ããªã®WOW64ãã£ã¬ã¯ããªã«ãããŸãã ãã¡ã€ã«CïŒ\ Program Files \ Firebird \ Firebird_2_5 \ WOW64 \ fbclient.dllãååŸãã次ã®ãã¹ã«ã³ããŒããŸãã
- PHPäœæ¥ãã£ã¬ã¯ããªDïŒ\ xampp \ php \
- SYSTEM32 Cã®å ŽåïŒ\ Windows \ System32 \ ã çè«çã«ã¯ãããã§ã³ããŒããå¿ èŠã¯ãããŸããããä»ã®ãããžã§ã¯ãã§ã©ã€ãã©ãªã䜿çšããŸããã·ã¹ãã å šäœã§ã³ããŒãäœæããªãããã«ãããã§ã³ããŒããŸãã
DïŒ\ xampp \ apache \ bin \ãžã®ã³ããŒãå§ããæ å ±æºããããŸãããç§ã®å Žåã¯äœã®åœ±é¿ããããŸããã ã¯ãããããŠãçè«çã«ã¯ã圱é¿ãäžããããšãã§ããŸããã§ãã ApacheãµãŒããŒã¯PHPãå®è¡ãã圌èªèº«ã¯è¿œå ã®ã¢ã¯ã»ã¹ã©ã€ãã©ãªãå¿ èŠãšããŸããã
ãŸããFirebirdã«ã¢ã¯ã»ã¹ããããã®PDOã©ã€ãã©ãªããã¡ã€ã«DïŒ\ xampp \ php \ ext \ php_pdo_firebird.dllã®å¯çšæ§ã確èªããããšããå§ãããŸã ã
ApacheãµãŒããŒãèµ·åãïŒäžã®å³ãåç §ïŒãXAMMPã³ã³ãœãŒã«ã§[éå§]ãã¯ãªãã¯ããŸãã çŸæç¹ã§ã¯ãFirebirdã®PDOãã©ã€ããŒãã·ã¹ãã ã«è¡šç€ºãããŠããããšã確èªããã®ã¯è¯ãããšã§ãããã©ã€ããŒãæ¥ç¶ãããŠããªãããšã«æ°ä»ããŸã§1æ¥ãéãããŸããã YII2ãšã©ãŒåŠçã·ã¹ãã ã¯ããã®åé¡ã®åŒ±ããã«ããŒã§ããããšãå€æããŸããã å¥ã®å Žæã§å¥ã®ãšã©ãŒãå ±åããŸããã Model Generator giiã®ããŒãã«ã®ãªã¹ãã¯èªã¿èŸŒãŸããããã®åã«Firebirdã«ã¢ã¯ã»ã¹ããããã®æ¡åŒµæ©èœã®ã€ã³ã¹ããŒã«äžã«ãšã©ãŒãçºçããããããšã©ãŒãæªæ¥ç¶ã®PDOãã©ã€ããŒã«é¢é£ä»ããããšã¯æããã§ã¯ãããŸããã§ããã
YII2 Dã®äœæ¥ãã£ã¬ã¯ããªã«test-fb.phpãã¡ã€ã«ãäœæããŸã ïŒ\ xampp \ htdocs \ yii \ framework ããã®äžã«ã³ãŒãããããŸãïŒ
<?php foreach (PDO::getAvailableDrivers() as $drv) { echo $drv."<br/>"; } ?>
ãã®ã³ãŒãã¯ãPHPã«æ¥ç¶ãããPDOãã©ã€ããŒããªã¹ãããŸãã ãã©ãŠã¶ãŒãèµ·åããã¢ãã¬ã¹ããŒã«localhost / yii / test-fb.phpãšå ¥åã ãããã«å¿çããŠãæ¥ç¶ããããã©ã€ããŒã®ãªã¹ããå«ãããŒãžãååŸããŸãã
firebird
mysql
sqlite
ãªã¹ãã«firebirdãã©ã€ããŒãããããšã確èªããŠãã ããã MySQLããã³SQLiteãã©ã€ããŒã¯ãããã©ã«ãã§åžžã«æ¥ç¶ãããŠããŸãã
Firebirdã«ã¢ã¯ã»ã¹ããããã®YII2æ¡åŒµæ©èœã®ã€ã³ã¹ããŒã«
YII2ã§Firebirdã«æ¥ç¶ããããã®2ã€ã®æ¡åŒµæ©èœããããŸãã
- yii2-firebirddb by Sergey Rusakov ã 説æããå€æãããšãYII1ããã®æ¡åŒµã®é©å¿ã§ãã æ¬ ç¹ã¯ã å®å®ããã¢ã»ã³ããªã§ã¯ãªãéçºã¢ã»ã³ããªã§ãããããå°æ¥ã composer.jsonã® ãæå°å®å®æ§ããå€æŽããå¿ èŠãããã Composerã䜿çšããŠã¢ããã°ã¬ãŒããããšãã«ä»ã®YII2æ¡åŒµæ©èœã®äžå®å®ãªããŒãžã§ã³ãèªã¿èŸŒãŸããããšã§ãã
- ãšãã¬ãŒãã»ãã¬ã€ã³ã»ã¡ã·ã¢ã¹ã«ããyii2-firebird ã ãã®æ¡åŒµã®ãœãŒã¹ãšåããã°ããå€æãããšãããã¯Sergey Rusakovã® yii2-firebirddbã§ãã ãdevãã©ã³ãããstableãã©ã³ãã«è»¢éãããŸãã
äž¡æ¹ã®æ¡åŒµæ©èœã®ã€ã³ã¹ããŒã«ãé çªã«èª¬æããŸãã yii2-firebirdã® 2çªç®ã®æ¡åŒµæ©èœããå§ããŸãã å®å®ããç¶æ ã§ãã
yii2-firebirdãã€ã³ã¹ããŒã«ãã
ãã¡ã€ã«DïŒ\ xampp \ htdocs \ yii \ composer.jsonãéãããã®äžã®ã³ãŒããèŠã€ããŸãã
... "require": { "php": ">=5.4.0", "yiisoft/yii2": ">=2.0.5", "yiisoft/yii2-bootstrap": "*", "yiisoft/yii2-swiftmailer": "*" ...
æåŸã«ãã³ã³ãè¡ã§åºåããããedgardmessias / yii2-firebirdãïŒ "*"ãè¿œå ããŸãã
... "require": { "php": ">=5.4.0", "yiisoft/yii2": ">=2.0.5", "yiisoft/yii2-bootstrap": "*", "yiisoft/yii2-swiftmailer": "*", "edgardmessias/yii2-firebird": "*" ...
è¿œå ãããè¡ã®åŸãã«ã³ãã¯æ¬¡ã®ããã«ããªãã§ãã ããã é åã®æåŸã«è¿œå ããã Composerã®å®è¡æã«ã³ã³ããååšãããšãšã©ãŒãçºçããŸãã PHPèªäœã§ã¯ãé åèŠçŽ ã®ãªã¹ãã®æ«å°Ÿã®éãæ¬åŒ§ã®åã«ã³ã³ãã䜿çšã§ããŸããã Composerã¯äœ¿çšã§ããŸããã
ãã®ããã Composerã«yii2-firebirdæ¡åŒµæ©èœãããŠã³ããŒãããå¿ èŠãããããšãææããŸããã ã³ãã³ãã©ã€ã³ãèµ·åããçŸåšã®ãã£ã¬ã¯ããªãDïŒ\ xampp \ htdocs \ yii \ã«ããŠã2ã€ã®ã³ãã³ããç¶ããŠæå®ããŸãã
composer update
composer install
Composerã®åºåã®ãšã©ãŒã泚ææ·±ã調ã¹ããã£ã¬ã¯ããªDïŒ\ xampp \ htdocs \ yii \ vendor \ edgardmessias \ yii2-firebird \ã®ååšã確èªããŸãã æ¡åŒµæ©èœãã€ã³ã¹ããŒã«ãããŸããã
ããŒã¿ããŒã¹ãžã®ã¢ã¯ã»ã¹ãèšå®ããŸãã yii2-firebirdã®ããã¥ã¡ã³ãã«ã¯ãèšå®ãå€æŽããå¿ èŠããããšæžãããŠããŸãã èšå®ãã¡ã€ã«DïŒ\ xampp \ htdocs \ yii \ config \ web.phpã泚ææ·±ã調ã¹ããšã次ã®è¡ïŒçŽ40è¡ç®ïŒãèŠã€ãããŸãã
'db' => require(__DIR__ . '/db.php'),
ãã¡ã€ã«DïŒ\ xampp \ htdocs \ yii \ config \ db.phpã§ããŒã¿ããŒã¹æ¥ç¶èšå®ãç·šéããå¿ èŠãããããšãæããã«ãªããŸãã ç§ãã¡ã¯ãããéããŠãã©ãŒã ã«æã£ãŠããŸãïŒ
<?php return [ 'class' => 'edgardmessias\db\firebird\Connection', 'dsn' => 'firebird:dbname=localhost:D:/WORK/database/TBOT.GDB;charset=WIN1251', 'username' => 'SYSDBA', 'password' => 'masterkey' ];
ããã€ãã®ç¹ã«æ³šæãæãããïŒ
- æ§æã®æåã®è¡ã¯ãåå空éãæã€Connectionã¯ã©ã¹ã瀺ããŠããŸã
- è¡'dsn'ã«ã¯ firebirdã¢ã¯ã»ã¹ãã©ã€ããŒã瀺ãããŠãããããŒã¿ããŒã¹ã®ãšã³ã³ãŒããè¡'dsn'ã«ç€ºãããŠããå¿ èŠããããŸãã
- ããŒã¿ããŒã¹ãžã®ãã¹ã¯ã¹ã©ãã·ã¥ãä»ããŠæå®ãããŸãããWindowsã§ã¯ããã¯ã¹ã©ãã·ã¥ãä»ããŠãã¹ãæå®ããã®ãäžè¬çã§ãã å®éãã©ã®ããã«è¡šç€ºãããã«éãã¯ãããŸããã DïŒ\ xampp \ htdocs \ yii \ vendor \ edgardmessias \ yii2-firebird \ src \ PdoAdapter.phpã¯ã©ã¹ã³ã³ã¹ãã©ã¯ã¿ãŒïŒè¡37ïŒã«ã³ãŒãããããŸãïŒ
... public function __construct($dsn, $username, $password, $driver_options = []) { // Windows OS paths with backslashes should be changed $dsn = str_replace("\\", "/", $dsn); ...
ã€ãŸã dsnè¡ã¯åžžã«ããã¯ã¹ã©ãã·ã¥ãè¡ã«çœ®ãæããŸãã - ããã¯ã¹ã©ãã·ã¥ã䜿çšãããšãã¯ãPHPã§æåããšã¹ã±ãŒãããããšãå¿ããªãã§ãã ãããããã¯ã¹ã©ãã·ã¥ã2åç¹°ãè¿ãå¿
èŠããããŸãã ã€ãŸã dsnè¡ã¯æ¬¡ã®ããã«ãªããŸãã
'dsn' => 'firebird:dbname=localhost:D:\\WORK\\database\\TBOT.GDB;charset=WIN1251',
- ããŒã«ã«ããŒã¿ããŒã¹ã«æ¥ç¶ããå Žåã dsnã§localhostãæå®ããå¿ èŠã¯ãããŸãããTCP/ IPã䜿çšããŠå€éšãµãŒããŒã«æ¥ç¶ããæ¹æ³ã瀺ããã ãã§ãã
yii2-firebirddbãã€ã³ã¹ããŒã«ãã
äžèšã§ç€ºããããã«ã yii2-firebirddbã®ã¹ããŒã¿ã¹ã¯devã§ããããããã®æ¡åŒµæ©èœã®ã€ã³ã¹ããŒã«ã«ã¯ããã€ãã®ãã€ããŒãªæ©èœããããŸãã
ããã§ããrequireãã»ã¯ã·ã§ã³ã®ãã¡ã€ã«DïŒ\ xampp \ htdocs \ yii \ composer.jsonã§ãæ¡åŒµåyii2-firebirddb
"srusakov/firebirddb": "*"
ã®ããŠã³ããŒããã¹ãè¿œå ããŸãã ã¹ããŒã¿ã¹ã©ã€ãã©ãªã¯devã§ããããã ãrequireãã»ã¯ã·ã§ã³ã§
"minimum-stability": "stable",
ã
"minimum-stability": "dev",
èŠã€ããŠå€æŽããŸãã ãã®ãã¥ãŒãååŸããŸãïŒæåãšæåŸã®è¡ã«æ³šæããŠãã ããïŒïŒ
... "minimum-stability": "dev", "require": { "php": ">=5.4.0", "yiisoft/yii2": ">=2.0.5", "yiisoft/yii2-bootstrap": "*", "yiisoft/yii2-swiftmailer": "*", "edgardmessias/yii2-firebird": "*" ...
Composerã«yii2-firebirddbæ¡åŒµæ©èœãããŠã³ããŒãããããã«æ瀺ããŸããã ã³ãã³ãã©ã€ã³ãèµ·åããçŸåšã®ãã£ã¬ã¯ããªãDïŒ\ xampp \ htdocs \ yii \ã«ããŠã2ã€ã®ã³ãã³ããç¶ããŠæå®ããŸãã
composer update
composer install
ãšã©ãŒããªãããšãããã³ãã£ã¬ã¯ããªDïŒ\ xampp \ htdocs \ yii \ vendor \ srusakov \ firebirddb \ã®ååšã確èªããŸãã æ¡åŒµæ©èœãã€ã³ã¹ããŒã«ãããŸããã
çºèš
yii2-firebirddbã®ããã¥ã¡ã³ãã«ã¯ãæ¡åŒµæ©èœãããŠã³ããŒãããããã«ãªããžããªãžã®ãã¹ãæå®ããå¿ èŠããããšæžãããŠããŸãã ç§ã®å Žåãããã¯ãšã©ãŒã«å ããŠæ©èœããŸããã§ãããã念ã®ããããã®æ¹æ³ã説æããŸãã
æåã« GIT for Windowsãã€ã³ã¹ããŒã«ããŸã ã https://git-scm.com/download/winããããŠã³ããŒãã§ããŸãã PATHç°å¢å€æ°ãæŽæ°ãããããã«ãã³ãã³ãã©ã€ã³ã³ã³ãœãŒã«ãåèµ·åããŸãã ã³ãã³ããæž¡ãã³ãã³ãã©ã€ã³ã確èªããŸã
git
å¿çãšããŠãã³ãã³ãã©ã€ã³ã§ãŠãŒãã£ãªãã£ã䜿çšãããšãã«ããã³ãââãã衚瀺ãããŸãã
ãã¡ã€ã«DïŒ\ xampp \ htdocs \ yii \ composer.jsonã§ã ãrequireãã»ã¯ã·ã§ã³ã®éãæ¬åŒ§ã®åŸã«ããªããžããªãžã®ãã¹ãèšè¿°ããŸãã
... "require": { "php": ">=5.4.0", "yiisoft/yii2": ">=2.0.5", "yiisoft/yii2-bootstrap": "*", "yiisoft/yii2-swiftmailer": "*", "edgardmessias/yii2-firebird": "*", "srusakov/firebirddb": "*" }, "repositories":[{ "type":"git", "url":"http://github.com/srusakov/yii2-firebirddb" }], ...
æåŸã®4è¡ã«æ³šæããŠãã ããã 次ã«ãæšæºã§ã³ãã³ãã©ã€ã³ãèµ·åããçŸåšã®ãã£ã¬ã¯ããªãDïŒ\ xampp \ htdocs \ yii \ã«ããŠã2ã€ã®ã³ãã³ããç¶ããŠæå®ããŸãã
composer update
composer install
ãšã©ãŒããªãããšãããã³ãã£ã¬ã¯ããªDïŒ\ xampp \ htdocs \ yii \ vendor \ srusakov \ firebirddb \ã®ååšã確èªããŸãã æ¡åŒµæ©èœãã€ã³ã¹ããŒã«ãããŸããã
ããŒã¿ããŒã¹æ¥ç¶æ§æãã¡ã€ã«DãéããŸãïŒ\ xampp \ htdocs \ yii \ config \ db.php ãå€æŽãå ãã以äžãååŸããŸãã
<?php return [ 'class' => 'yii\db\Connection', 'dsn' => 'firebird:dbname=localhost:D:/WORK/database/TBOT.GDB;charset=WIN1251', 'username' => 'sysdba', 'password' => 'masterkey', 'charset' => 'utf8', // , 'pdoClass' => 'srusakov\firebirddb\PDO', 'schemaMap' => [ 'firebird' => 'srusakov\firebirddb\Schema' // FireBird ] ];
ãã«ã¹ãã§ãã¯
æ¡åŒµæ©èœããã©ã€ããŒãããã³ããŒã¿ããŒã¹æ¥ç¶ãã©ã¡ãŒã¿ãŒã®æ£ããã€ã³ã¹ããŒã«ã確èªããæãç°¡åãªæ¹æ³ã¯ãæ¥ç¶ããããšã§ãã YII2ããgiiãŠãŒãã£ãªãã£ãèµ·åãã Model GeneratorãéããŸãã gii httpãéãããã®ãªã³ã¯ïŒ// localhost / yii / web /ïŒR = gii ã Model Generatorã»ã¯ã·ã§ã³ã®[Start]ãã¿ã³ãéžæããããçŽæ¥ãªã³ã¯httpïŒ//localhost/yii/web/index.phpïŒR = giiã䜿çšããŸã/ default / viewïŒid = model
Model Generatorããšã©ãŒãªãã§éãå Žåããã¹ãŠãã€ã³ã¹ããŒã«ãããŠãããæ£åžžã«åäœããŠããŸãã Model Generatorã¯ãããŒã¿ããŒã¹ããŒãã«ã®ãªã¹ããèªã¿èŸŒã¿ãŸãã Firebirdã«æ¥ç¶ããŸãã ããŒãžã®èªã¿èŸŒã¿ãšã©ãŒãçºçããå Žåãã»ãšãã©ã®å ŽåãããŒã¿ããŒã¹ã«ããŒãã«ããªããããŒãã«ã®ãªã¹ãã¯ç©ºã§è¿ãããŸãã å°ãªããšã1ã€ã®ããŒãã«ãäœæããŠãåè©Šè¡ããŠãã ããã ãŸããæ§æå ã®ããŒã¿ããŒã¹ãžã®æ£ãããã¹ã確èªããŸãïŒãã¡ã€ã«DïŒ\ xampp \ htdocs \ yii \ config \ db.php ïŒã
ãããã«
- æ¡åŒµæ©èœã®åäœã«å¯Ÿããã¢ãããŒãã®éãã«æ³šæããŠãã ããã yii2-firebirddbæ¡åŒµæ©èœã¯ãæšæºã®YII2åå空éã®Connectionã¯ã©ã¹ã§æ©èœããŸãããç¬èªã®PDOãã©ã€ããŒã䜿çšããŠFirebirdã«ã¢ã¯ã»ã¹ããŸãã yii2-firebirdæ¡åŒµæ©èœã¯ãæšæºã®æ¥ç¶ãç¬èªã«æ¡åŒµããŸãã
- äž¡æ¹ã®æ¡åŒµæ©èœã¯BLOBãã£ãŒã«ãã§ã¯æ©èœããŸããã ãã®ãã°ã®èª¬æã¯https://bugs.php.net/bug.php?id=61183ã«ãããŸã ã ããã¯ç§ã«ã¯ããŸãé¢ä¿ããªãã®ã§ããã®åé¡ã«å¯ŸåŠããŸããã§ãããblobãã£ãŒã«ããvarcharã«å€æãããã¥ãŒãããŒã¿ããŒã¹ã«äœæããããšãææ¡ããŸãã ããã«ã varcharã¯æ倧32Kbã®ããã¹ããµã€ãºãèš±å¯ããŸãã ã¡ãã£ã¢ïŒåçããã¥ãŒãªã©ïŒã®å Žåãããã§ã¯ååã§ã¯ãããŸããããäž»ã«ããã¹ãããŒã¿ã§äœæ¥ããããã§ååã§ãã 2çªç®ã®ãªãã·ã§ã³ã¯ãã°ã®èª¬æãèªãããšã§ãããããä¿®æ£ããããããé©çšããããšããå§ãããŸãã 誰ãããããè¡ããšãã³ã¡ã³ãã®è³Œèªãäžæ¢ããèšäºã«å€æŽãå ããŸãã
- PHPãšYII2ãé·ãé䜿çšããŠããããã°ã©ããŒã«ãšã£ãŠããã®è³æã¯äžå¿ èŠã«è©³çŽ°ã«èŠãããããããŸããã ããšãã°ãå€ãã®å Žåããæ§æãå€æŽããããšèšãã ãã§ååã§ãã ãã ããDelphiããPHPããã³YII2ãžã®ç§»è¡ãéå§ãã人ã«ãšã£ãŠã¯ããã®ãããªãã¬ãŒãºã¯ã»ãšãã©ãããŸããã æ§æãååšãããã¡ã€ã«ãèŠã€ããå¿ èŠããããŸãã æ¡åŒµæ©èœãæŽæ°ããã³ãã³ãã«ãåãããšãåœãŠã¯ãŸããŸãã