2017 © Pedro Peláez
 

library dev-pdo-statement

A PDOStatement for develop

image

koriym/dev-pdo-statement

A PDOStatement for develop

  • Thursday, February 25, 2016
  • by koriym
  • Repository
  • 1 Watchers
  • 10 Stars
  • 2,813 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 6 % Grown

The README.md

A PdoStatement for Developers

Continuous Integration, (*1)

[Japanese], (*2)

koriym/dev-pdo-statement log following information to help your sql inspection., (*3)

  • Query excution time.
  • Final SQL query with parameter values interpolated into it from prepared statement.
  • The result of EXPLAIN query.
  • The result of SHOW WARNINGS query.

Install

AttachDevPdoStatementclass to the target $pdo., (*4)

use Koriym\DevPdoStatement\DevPdoStatement;
use Koriym\DevPdoStatement\Logger;

$pdo->setAttribute(\PDO::ATTR_STATEMENT_CLASS, [DevPdoStatement::class, [$pdo, new Logger]]);

Then $pdo start to log as following on each query., (*5)

time:0.00035190582275391 query: INSERT INTO user(id, name) VALUES (99, 'koriym99')
time:0.00020503997802734 query: SELECT id, name FROM user where id > 80
warnings:[
    {
        "Level": "Note",
        "Code": "1003",
        "Message": "\/* select#1 *\/ select `tmp`.`user`.`id` AS `id`,`tmp`.`user`.`name` AS `name` from `tmp`.`user` where (`tmp`.`user`.`id` > 80)"
    }
]
explain :[
    {
        "id": "1",
        "select_type": "SIMPLE",
        "table": "user",
        "partitions": null,
        "type": "ALL",
        "possible_keys": null,
        "key": null,
        "key_len": null,
        "ref": null,
        "rows": "100",
        "filtered": "33.33",
        "Extra": "Using where"
    }
]

Custom Log

You can implement custom condition for logging or choose your favorite logger., (*6)

use Koriym\DevPdoStatement\LoggerInterface;

class MyPsr3Logger implements LoggerInterface
{
    /**
     * {@inheritdoc}
     */
    public function logQuery($query, $time, array $explain, array $warnings)
    {
        // log or throw exception in your custom condition.
    }
}

Demo

php doc/demo/run.php 

The Versions

25/02 2016

1.x-dev

1.9999999.9999999.9999999-dev

A PDOStatement for develop

  Sources   Download

MIT

pdo

24/02 2016

0.1.0

0.1.0.0

A PDOStatement for develop

  Sources   Download

MIT

pdo