2010-10-19

How to use MySQL with FLOW3

If you download FLOW3 and set the file permissions as needed after unpacking, it runs out of the box, using SQLite for the persistence layer. FLOW3 can use other databases for which a PDO driver exists though (YMMV), and in the last weeks I have seen question on using MySQL with FLOW3 appear ever more often.



Setting up your database

First of all you need to create a database for FLOW3 to use with whatever means you usually use for that purpose. I'd do it like this:
mysqladmin5 -p create flow3
Then you need to create the needed tables, the DDL is in a file that comes with the FLOW3 package:
mysql5 -p flow3 < Packages/Framework/FLOW3/Resources/Private/Persistence/SQL/DDL.sql

Note: This will only work if you have your MySQL configured to run in ANSI SQL mode, something you want to do anyway...

Configure FLOW3 for MySQL

Now all that is left is to tell FLOW3 to actually use that shiny MySQL database. For this you need to add some lines to Configuration/Settings.yaml in the root of your FLOW3 installation (create the file if you don't have one yet):
FLOW3:
  persistence:
    backendOptions:
      dataSourceName: 'mysql:host=<host>;dbname=blog'
      username: '<username>'
      password: '<password>'

Keep in mind this is YAML, so it must be indented using spaces. You have more options for the DSN, e.g. to use a socket for the connection.

Why so complicated?

If you wonder why it can work out of the box with SQLite but not with MySQL, here's why: SQLite only needs a database file for eternal happiness. So when FLOW3 tries to connect to the database there is one case it handles in a special way: when using the SQLite PDO driver and the expected file does not exist. Then it can simply create the database (file) and set up the tables, as it doesn't need to know any more parameters and can create the database without hassle.
For other databases the ways of creating databases differ wildly, so we didn't even try to handle that, yet.

2 comments:

John Barness said...

Thanks for the helpful article.
You see, I experienced the similar issue when needed to adapt the huge amount of business data to secure data room. Your method helps.

Toby Valentine said...

The cloud offers non-stop accessibility to client data, while providing secure access as designated by the clients. The data, in turn, may be stored across one or many servers, configured by the cloud hosting company in their data centers.
data room free