SQLite ééç¿
ãã£ããSQLiteãéç¿ãã¦ã¿ã¾ãã(æ¥åã§ã¯å ¨ããå人çã«ãå ¨ã触ã£ã¦ãªãã£ãã®ã§)ã ã»ã¼è¦ãæ¸ãç¨åº¦ãªã®ã§ãã¡ããã¨ããå 容ã¯ã¡ããã¨ããã¨ããã§èª¿ã¹ã¦ãã ãã(ç¬
確èª
sqlite3 -version
ãªãã£ããã¤ã³ã¹ãã¼ã«
sudo dnf install sqlite
databaseé åä½æ&æ¥ç¶
sqlite3 test.db
DDLæµãè¾¼ã¿
ã¦ãã¨ãã«
## ãã¼ãã«ã®ç¢ºèª .tables ## ã¹ãã¼ã(ãã¼ãã«æ å ±)ã®è¡¨ç¤º(ãã¼ãã«åçç¥ããã¨ãå ¨é¨åºã?) .schema [ãã¼ãã«å] ## databaseã®ç¢ºèª(ãã£ã¨ãã¨PHPã®æã®DSNä½ãã®æ¥½) .databases ## ååã表示 .header on ## ã¢ã¼ãå¤æ´ãã¦è¦ããã .mode column ## ãã£ã¡ã¯ \G ã¿ãããªæã .mode line ## SQLãã¡ã¤ã«ãèªã¿è¾¼ãã§å®è¡ .read ãã¡ã¤ã«.sql ## ããã¯ã¢ãã .backup backup.YYMMDD.db ## ãªã¹ã㢠.restore backup.YYMMDD.db ## æãã( ctrl-C ã§ãããããã©) .q
PHPã§éæ¥ç¶
<?php $dsn = 'sqlite:/home/gallu/test/test.db'; $pdo = new PDO($dsn); var_dump($pdo);
å è¦ãæ¸ã
varcharã¨ãæå®ã§ãããããã®ã§ããå é¨çã«ã¯ä»¥ä¸ã«ãããããã¡ããããã§ãã
NULL NULLå REAL æµ®åå°æ°ç¹ INTEGER æ´æ° TEXT ä»»æã®æåå BLOB ä»»æã®ãã¤ããªãã¼ã¿
phinx確èª
composer require robmorgan/phinx vendor/bin/phinx init mkdir -p db/migrations db/seeds
phinx.php
return [ 'paths' => [ 'migrations' => '%%PHINX_CONFIG_DIR%%/db/migrations', 'seeds' => '%%PHINX_CONFIG_DIR%%/db/seeds' ], 'environments' => [ 'default_migration_table' => 'phinxlog', 'default_environment' => 'development', 'development' => [ 'adapter' => 'sqlite', 'name' => '/home/gallu/test/test.db', ], ], 'version_order' => 'creation' ];
ã£ã¦æ¸ããã /home/gallu/test/test.db.sqlite3 ã£ã¦ãªã£ããæ¡å¼µå .sqlite3 ãããã©ã§ã¤ãã½ãã å¾ã¯å¤§ä½ä¸ç·ã½ã å¤åæ±ç¨çã«èãã¦
return [ 'paths' => [ 'migrations' => '%%PHINX_CONFIG_DIR%%/db/migrations', 'seeds' => '%%PHINX_CONFIG_DIR%%/db/seeds' ], 'environments' => [ 'default_migration_table' => 'phinxlog', 'default_environment' => 'development', 'development' => [ 'adapter' => 'sqlite', 'name' => __DIR__ . '/test.db', ], ], 'version_order' => 'creation' ];
ããããã ãããªãç´ä¸ã«ç½®ããã©ããã¯ã¨ãããã¨ã㦠__DIR__ 使ãã°ãã©ãã«ããã¦ãåé¡ãªããã
ãã¤ã°ã¬ã¼ã·ã§ã³ã®ç¢ºèªã
php vendor/bin/phinx create TestTable
public function change(): void { $table = $this->table('test'); $table->addColumn('name', 'string') ->addColumn('str', 'string', ['limit' => 128]) ->addColumn('str2', 'varbinary', ['limit' => 128]) ->addColumn('num', 'integer', ['comment' => 'ã³ã¡ã³ã']) ->addColumn('num2', 'biginteger') ->addColumn('created_at', 'datetime') ->create(); }
ã§
php vendor/bin/phinx migrate --dry-run
ããã®
php vendor/bin/phinx migrate
ã§ãããªãã ãã大ä½ææ¡ããªããã§ãã£ã³ã¹ãã£ãã使ã£ã¦ã¿ãããã?