Tag Archives: DBMS

Database available in FuelPHP


I wondered what database is available in FuelPHP, and look into FuelPHP code.

Environment

  • FuelPHP 1.8 (GitHub)

Available Database

The following DBMS is theoretically available in FuelPHP. It means that FuelPHP use driver for the following databases.

  • Cubrid
  • FreeTDS
  • Microsoft SQL Server
  • Sybase
  • Firebird
  • IBM DB2
  • IBM Informix Dynamic Server
  • MySQL
  • Oracle Call Interface
  • ODBC v3 (IBM DB2, unixODBC and win32 ODBC)
  • PostgreSQL
  • SQLite 3, 2
  • SQL Azure
  • 4D

How to investigate

First, read manual. At the section Database Introduction, it says Can be mysql, mysqli or pdo. Namely, FuelPHP can handle mysql specific driver and PDO driver.

Then, read PDO section of PHP document. For above all DBMS, PDO is available.

Well, can FuelPHP handle PDO and connect to DB in real? Now, look at the FuelPHP core code, which handle database connection. There are 3 kind of connection.php, each of them handle mysql, mysqli, PDO connection. It’ll be clear PDO is available in FuelPHP.

Take your Attention when you use sqlite

You should be careful when you use sqlite. (FuelPHP version 1.7.2)

Primary Key

Migration doesn’t work when you add Primary Key like MySQL. In sqlite3, we can’t add name to Primary Key. 例えば MySQL なら Primary Key id (id) となるところが、 sqlite3 だと Primary Key (id) というようになります。

So, we should create plain SQL or change FuelPHP core code. It’s a choice not to use Primary Key, but I don’t recommend.

また通常は migration file を php oil を使って作成すると 自動で UNSIGNEDid が作成されて AUTO_INCREMENT が設定されますが、 sqlite ではこれが動きません。 sqlite では AUTO_INCREMENT ではなく AUTOINCREMENT になります。 いまのところ自動生成のスクリプトでは対応していませんので FuelPHP の core のコードを変更する必要があります。 そして自動生成される UNSIGNED は 削除しましょう。 sqlite では UNSIGNED BIT INT というのが使えますが、 使ったところで INTEGER と解釈されます。

Blank Charset

sqlite3 では charset の指定方法が他のデータベースとは異なります。 PRAGMA statement を使います。 (確か sqlite3 では標準文字コードが utf-8 だったと思います。)

If you don’t set charset in db config (config/db.php), php oil migrate occurs an error of SQL, CREATE TABLE, because SQL which contains DEFAULT CHARACTER SET utf8 at last is executed. To prevent that, set empty string to charset, charset => ''. すると、 DEFAULT から始まる文字コード指定部分がなくなり、 sqlite3 でも php oil migrate が動くようになります。

db.php は次のように書きます。

このようにすると、 環境ごとに別の DB が作成されます。 table_prefixphp oil r migration の時には不要ですが、 php oil r migration:down の時に必要になることがあります。

Take your Attention when you use PostgreSQL

Migration doesn’t work. It is because PostgreSQL SQL syntax is somehow different from MySQL one. I recommend you to use FuelPHP Plugin for PostgreSQL.


pg_dump: How to Export only Table Scheme or Data


pg_dump with -s , -a option is used on exporting only table scheme or data.

Continue reading pg_dump: How to Export only Table Scheme or Data

Oracle: Concatenate Strings in Grouping


Sorry, this entry is only available in Japanese.