catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.83k stars 1.15k forks source link

medoo error return null data #366

Closed Walk4Muscle closed 3 years ago

Walk4Muscle commented 8 years ago

I am using medoo to handle table operations. And now I cannot debug via error() function of medoo at http://medoo.in/api/error.

Here is my test table structure:

CREATE TABLE [user] (
[id] INTEGER  PRIMARY KEY AUTOINCREMENT NOT NULL,
[username] NVARCHAR(50)  UNIQUE NOT NULL,
[email] NVARCHAR(50)  UNIQUE NOT NULL,
[password] VARCHAR(255)  NULL,
[displayname] NVARCHAR(255)  NULL
)

And the test code snippet:

$db = new medoo([
        'database_type' => 'sqlite',
        'database_file' => 'db/test.s3db',
    ]);
    $r = $db->insert('user', ['username' => '<existing data in table>', 'email' => '<existing data in table>']);
    var_dump($r);
    var_dump($db->error());

And I always get the array via $db->error():

[0]=> string(5) "00000" [1]=> NULL [2]=> NULL

However, as the columns are set as unique, so it should return error messages. How to fix it? Any hints are appreciated.

ghost commented 8 years ago

@Walk4Muscle , Can you post the output of $db->last_query after running your query? Thanks!

Walk4Muscle commented 8 years ago

@omaressa , thanks for your reply. And yes, it returns "INSERT INTO "user" ("username", "email") VALUES ('user', 'user@domain.com')"

rakshazi commented 8 years ago

@catfan @omaressa same problem

rakshazi commented 8 years ago

@catfan @omaressa @Walk4Muscle problem has been solved! Just add following lines to your database config:

'option' => [
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
        ],
Jackysi commented 6 years ago

I am new Medoo user and I would be very happy if this would be some how explained on Documentation ^^. Luckily Google search returns this issue quickly!

rakshazi commented 6 years ago

@Jackysi read docs - https://medoo.in/api/new (section "Configuration")

pluveto commented 4 years ago

Same problem.

debug show it executed

SELECT COUNT(`id`) FROM `orders` WHERE `createdAt` >= 1582243200 AND `createdAt` < 1582329600

And I executed the above manually, it works. But medoo return null.