GithubHelp home page GithubHelp logo

Uncaught TypeError: Argument 1 passed to FaaPz\PDO\DatabaseException::__construct() must be of the type string, null given about pdo HOT 15 CLOSED

nixoncode avatar nixoncode commented on June 10, 2024
Uncaught TypeError: Argument 1 passed to FaaPz\PDO\DatabaseException::__construct() must be of the type string, null given

from pdo.

Comments (15)

kwhat avatar kwhat commented on June 10, 2024

How did you construct the Database object? I suspect you inadvertently passed null instead of the DSN.

from pdo.

nixoncode avatar nixoncode commented on June 10, 2024

I have the database object initialized correctly, other queries are running well

from pdo.

kwhat avatar kwhat commented on June 10, 2024

Maybe a basic example of how to duplicate the problem would help me understand what is happening.

from pdo.

nixoncode avatar nixoncode commented on June 10, 2024

I somehow managed to fix it by using date() function instead of Faapz new Raw('NOW()')

$this->db->update(['last_seen' => date('Y-m-d H:i:s')])
                ->table('users')
                ->where(new Conditional('id', '=', 1))
                ->execute();

The initial query was like this

 $this->db->update(['last_seen' => new Raw('NOW()')])
                ->table('users')
                ->where(new Conditional('id', '=', 1))
                ->execute();

how can I use MySQL's now Function without using the PHP date?

from pdo.

nixoncode avatar nixoncode commented on June 10, 2024

Maybe a basic example of how to duplicate the problem would help me understand what is happening.

the queries above can help?

from pdo.

kwhat avatar kwhat commented on June 10, 2024

Yes that helps, I will need to do a little testing on my side. I will get back to you shortly.

from pdo.

kwhat avatar kwhat commented on June 10, 2024

Hm, so I noticed that you are getting a DatabaseException so I think you are using 2.0.0? The DatabaseException was removed in 2.0.1 due to some issues with __toString and throwing Exceptions. Is it possible to try with 2.0.1 and provide a stack trace if it crashes?

from pdo.

nixoncode avatar nixoncode commented on June 10, 2024

16039518378135421810261179010498
Am already using 2.0.1

from pdo.

kwhat avatar kwhat commented on June 10, 2024

Raw clause is broken.

from pdo.

kwhat avatar kwhat commented on June 10, 2024

There is also another bug with the list($state, $code, $message) = $stmt->errorInfo(); code in the AbstractStatement i'll take a look at it for 2.1.

from pdo.

kwhat avatar kwhat commented on June 10, 2024

Quick question, I presume you are using PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT or PDO::ERRMODE_WARNING. How do you check for errors in your code? How would you prefer to check for errors on ->execute() without exceptions? I was thinking though a couple of options for this library: execute could return bool false or return the PDOStatement object where ->errorCode() could be used. Let me know what you think would work best.

from pdo.

kwhat avatar kwhat commented on June 10, 2024

Fix:

diff --git a/src/Statement/Update.php b/src/Statement/Update.php
index 345adde..d34de6e 100644
--- a/src/Statement/Update.php
+++ b/src/Statement/Update.php
@@ -72,7 +72,14 @@ class Update extends AdvancedStatement
      */
     public function getValues(): array
     {
-        $values = array_values($this->pairs);
+        $values = [];
+        foreach ($this->pairs as $value) {
+            if ($value instanceof QueryInterface) {
+                $values = array_merge($values, $value->getValues());
+            } else {
+                $values[] = $value;
+            }
+        }
 
         if ($this->where !== null) {
             $values = array_merge($values, $this->where->getValues());

from pdo.

nixoncode avatar nixoncode commented on June 10, 2024

Quick question, I presume you are using PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT or PDO::ERRMODE_WARNING. How do you check for errors in your code? How would you prefer to check for errors on ->execute() without exceptions? I was thinking though a couple of options for this library: execute could return bool false or return the PDOStatement object where ->errorCode() could be used. Let me know what you think would work best.

Am using the Default, I checked the code and saw PDO::ERRMODE_EXCEPTION was already set. I always do this when using raw PDO.

Am currently handling errors by wrapping everything in a try-catch and listen for errors on FaaPz\PDO\DatabaseException I think that works just fine, in the past I would do \PDOException. I think exceptions is the best way to go since PDO does that as well.

from pdo.

nixoncode avatar nixoncode commented on June 10, 2024

There is also another bug with the list($state, $code, $message) = $stmt->errorInfo(); code in the AbstractStatement i'll take a look at it for 2.1.

Yes, at times null is returned for the message. I don't know why. I remember making the message nullable on the DatabaseException class

public function __construct(?string $message = '', string $code = 'database_error', Exception $previous = null)
    {
        parent::__construct($mes sage, 0, $previous);
        $this->code = $code;
    }

from pdo.

kwhat avatar kwhat commented on June 10, 2024

I published 2.1 which fixes your issue. I think it has something to do with the mysql pdo driver not having a msg for that particular error code. Either way, DatabaseException has gone away and I simplified a few things to make it easier to work with. Let me know if you run into any other issues.

from pdo.

Related Issues (20)

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.