Comments (15)
How did you construct the Database object? I suspect you inadvertently passed null instead of the DSN.
from pdo.
I have the database object initialized correctly, other queries are running well
from pdo.
Maybe a basic example of how to duplicate the problem would help me understand what is happening.
from pdo.
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.
Maybe a basic example of how to duplicate the problem would help me understand what is happening.
the queries above can help?
from pdo.
Yes that helps, I will need to do a little testing on my side. I will get back to you shortly.
from pdo.
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.
from pdo.
Raw clause is broken.
from pdo.
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.
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.
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.
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.
There is also another bug with the
list($state, $code, $message) = $stmt->errorInfo();
code in theAbstractStatement
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.
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)
- Email and domain not working? HOT 1
- MD5 of column value in where clause HOT 1
- Error when setting charset HOT 1
- Join not working properly HOT 4
- Use MySQL function and column as conditional value HOT 6
- Invalid value for insert statement when trying to insert NULL HOT 4
- Insert execute no longer return new id HOT 1
- How to use Clasule RAW HOT 2
- Creating the WHERE clause HOT 1
- Inserts are duplicated HOT 1
- Error in docs of update HOT 1
- Insert Many Table HOT 1
- Help needed on insert statement HOT 14
- Update about text "Just another PDO database library" HOT 1
- lastinsertid removed? HOT 2
- README not up to date HOT 4
- orderBy is not rendered when optional direction is omitted HOT 2
- Limit is treated as a string HOT 7
- Between condition with parentheses lead to strange state HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pdo.