Coder Social home page Coder Social logo

atlas.pdo's People

Contributors

adamdyson avatar consatan avatar dbraff avatar mrpetovan avatar n1215 avatar pmjones avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

atlas.pdo's Issues

ConnectionLocator cannot be used with PDO Persistent Connections

Hi, I was looking into integrating this library with an existing application and while running a small test I found an a compatibility issue between the ConnectionLocator class and use of PDO::ATTR_PERSISTENT. It seems that the ConnectionLocator->newConnection() method always calls the Connection->logQueries() method, which in turn sets the attribute PDO::ATTR_STATEMENT_CLASS. According to the PDO documentation (https://www.php.net/manual/en/pdo.setattribute.php), these two attribute settings cannot be used together:

PDO::ATTR_STATEMENT_CLASS: Set user-supplied statement class derived from PDOStatement. Cannot be used with persistent PDO instances. Requires array(string classname, array(mixed constructor_args)).

This would also be an issue if you instantiated a Connection object and called it's logQueries() method, but in the case of the ConnectionFactory it happens automatically.

<?php

use Atlas\Pdo\ConnectionLocator;

require_once __DIR__ . '/vendor/autoload.php';

...

$connectionLocator = ConnectionLocator::new(
    $dsn,
    $username,
    $password,
    [
        PDO::ATTR_PERSISTENT => true,
    ]
);

$connection = $connectionLocator->getDefault();

Running the above sample code will produce the following exception:

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: PDO::ATTR_STATEMENT_CLASS cannot be used with persistent PDO instances in ...

I think this is an excellent package and would love to be able to use it in my organization. I would be happy to submit a PR for this issue or alternatively to add to the documentation so it is known that persistent connections are not compatible with this package if that is the desired approach.

Thank you,
Daniel Braff

LoggedStatement::bindColumn() does not work

@dbraff see current 1.x branch, in tests/LoggedStatementTest::testBindColumn().

It appears that the double-indirection-by-reference does not work when binding a variable to a column result. Although I suppose it's not critical, it does represent a BC break. Any ideas on how to get that working?

If there can be no straightforward solution, I may have to break LoggedStatement into two classes: one for "transient" connections, that looks a lot like the v1.1.2 LoggedStatement, and one for "persistent" connections, that does not support bindColumn(). (See #16 for what that would look like.)

Logging connection time

Hi,

I think it will be interesting to save the connection to the database, with a connection time.
This can be good information for debugging an unusually slow application, due to the slow PDO connection, for example.

The statement for logging can be: "CONNECTION"

Regards.

2.0

Hello .. thanks for a very useful libraries...
A question: is 2.0 production ready, recommended for production use..
Thanks
Johan

Logging bad request

Hi,

In case of bad SQL request, a PDO exception is throwed.
But logging appears after a good execution. Possible to do perform the logging in all cases with result (true/false) ?

Example of simple implementation to do that:

    public function commit() : bool
    {
        $executionPerformed = false;
        $entry = $this->newLogEntry(__METHOD__);

        try {
            $result = $this->pdo->commit();
            $executionPerformed = true;
        } finally {
            $entry['performed'] = $executionPerformed;
            $this->addLogEntry($entry);
        }

        return $result;
    }

Regards.

Instance LoggedStatement create from native PDO::prepare cannot execute

$connectionLocator = \Atlas\Pdo\ConnectionLocator::new(
    'mysql:dbname=db;host=127.0.0.1',
    'user',
    'pswd'
);
$connectionLocator->logQueries(true);

$pdo = $connectionLocator->getDefault()->getPdo();

// SQLBuilder is a 3th-party open source library
// 1st argument MUST BE a PDO instance
$sqlbuilder = new SQLBuilder($pdo);

// In the query method, will prepare the SQL and execute it
$result = $sqlbuilder->query('select * from user where id=?', $id)->fetchAll();

// The SQLBuilder query method look like this
function query(string $sql, ...$bind): PDOStatement
{
    $stm = $this->pdo->parepare($sql);
    foreach ($bind as $k => $v) {
        $stm->bindValue($k + 1, $v);
    }
    // LoggedStatement->execute() will throw an Error
    // Function name must be a string
    // at line 41
    return $stm->execute();
}

Because ConectionLocator enable the logQueries, the PDO::ATTR_STATEMENT_CLASS will set to the LoggedStatement class.

In SQLBuilder the LoggedStatement is create from native PDO::prepare method, so not call the LoggedStatement::setLogEntry and LoggedStatement::setQueryLogger. Then when run LoggedStatement->execute(), it will throw this error.

The SQLBuilder only required a PDO instance, I don't think this requirement is too much. So I think it's Atlas PDO issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.