<commit_before>[[https://travis-ci.org/etu/php-tools][https://travis-ci.org/etu/php-tools.svg?branch=master]]

* Install with composer:
composer.json
#+NAME: composer.json
#+BEGIN_SRC json
{
    "repositories": [
        {
            "url": "https://github.com/etu/php-tools.git",
            "type": "git"
        }
    ],
    "require": {
        "etu/ET": "dev-master"
    }
}
#+END_SRC

* Example usage of Config and Db

config.ini
#+NAME: config.ini
#+BEGIN_SRC ini
[@]
db.dsn = 'sqlite::memory:'
db.username =
db.password =

[example.com]
db.username = live

[*.dev.example.com]
db.username = dev
#+END_SRC

test.php
#+NAME: test.php
#+BEGIN_SRC php
<?php
require('vendor/autoload.php');

// Second param, env, is optional. But matches titles in ini file to load config.
$config = new Etu\PhpTools\Config('config.ini', 'optional.example.com');
$db = new Etu\PhpTools\Db($config, new Etu\PhpTools\Db\PdoBackend());

$db->query('CREATE TABLE names(id INTEGER PRIMARY KEY, name VARCHAR(10));');
$db->query('INSERT INTO names(id, name) VALUES (NULL, "Alice");');
$db->query('INSERT INTO names(id, name) VALUES (NULL, "Bob");');

print_r(
    $db->query(
        'SELECT * FROM names WHERE name = :name',
        [':name' => 'Alice']
    )->fetchAll()
);
#+END_SRC<commit_msg>Updated readme example to use ini-config<commit_after>[[https://travis-ci.org/etu/php-tools][https://travis-ci.org/etu/php-tools.svg?branch=master]]

* Install with composer:
composer.json
#+NAME: composer.json
#+BEGIN_SRC json
{
    "repositories": [
        {
            "url": "https://github.com/etu/php-tools.git",
            "type": "git"
        }
    ],
    "require": {
        "etu/ET": "dev-master"
    }
}
#+END_SRC

* Example usage of Config and Db

config.ini
#+NAME: config.ini
#+BEGIN_SRC ini
[@]
db.dsn = 'sqlite::memory:'
db.username =
db.password =

[example.com]
db.username = live

[*.dev.example.com]
db.username = dev
#+END_SRC

test.php
#+NAME: test.php
#+BEGIN_SRC php
<?php
require('vendor/autoload.php');

// Second param, env, is optional. But matches titles in ini file to load config.
$config = new Etu\PhpTools\IniConfig('config.ini', 'optional.example.com');
$db = new Etu\PhpTools\Db($config, new Etu\PhpTools\Db\PdoBackend());

$db->query('CREATE TABLE names(id INTEGER PRIMARY KEY, name VARCHAR(10));');
$db->query('INSERT INTO names(id, name) VALUES (NULL, "Alice");');
$db->query('INSERT INTO names(id, name) VALUES (NULL, "Bob");');

print_r(
    $db->query(
        'SELECT * FROM names WHERE name = :name',
        [':name' => 'Alice']
    )->fetchAll()
);
#+END_SRC
{'fraction_non_alphanumeric': 0.18986852281515854, 'fraction_numerical': 0.0015467904098994587, 'mean_word_length': 3.5148342059336826, 'pattern_counts': {'":': 10, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1134918', 'n_tokens_mistral': 988, 'n_tokens_neox': 954, 'n_words': 212}