PhpTide wraps database access behind a shared Db layer so you do not write driver-specific code—drivers are selected from configuration.
Supported backends include MySQL, SQL Server, PostgreSQL, SQLite, Oracle, InterBase, Mongo, and PDO-backed drivers.
Define credentials in config—several styles are supported.
Typical array config (in app/config.php or a module config such as app/home/config.php):
// Database
'db_type' => 'mysql',
'db_host' => 'localhost',
'db_name' => 'phptide',
'db_user' => 'admin',
'db_pass' => '123456',
'db_port' => 3306,
'db_charset'=> 'utf8',PDO DSN shortcut — user:password@driver-dsn (user/password optional):
MySQL:
'db_dsn'=> 'root:123456@mysql:host=localhost;port=3306;dbname=phptide;charset=utf8'SQLite:
'db_dsn'=> 'sqlite:zidian_full.db'Master / replicas
Set 'db_deploy' => true and list multiple hosts separated by commas:
'db_deploy' => true,
'db_type' => 'mysql',
'db_host' => 'localhost1,localhost2',
'db_name' => 'phptide',
'db_user' => 'admin1,admin2',
'db_pass' => '123456,654321',
'db_port' => 3306,
'db_charset'=> 'utf8',By default reads and writes are not split; see below for read/write separation.
Read / write splitting
Use with 'db_deploy' => true when you have multiple servers:
'db_deploy' => true,
'db_rw_separate' => true,
'db_type' => 'mysql',
'db_host' => 'localhost1,localhost2',
'db_name' => 'phptide',
'db_user' => 'admin1,admin2',
'db_pass' => '123456,654321',
'db_port' => 3306,
'db_charset'=> 'utf8',The first configured host is treated as the writer unless you change counts:
'db_master_num' => 1,
'db_slave_no' => '',The ORM picks read vs write automatically. If you run raw SQL, follow the convention: writes go through exec, reads through query, otherwise master/slave routing can be wrong.