catfan / Medoo

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

Prefix is doubled in table create method #963

Closed rvalitov closed 3 years ago

rvalitov commented 3 years ago

Describe the bug When I create a database with prefix option in config, the resulting table has a doubled prefix. This happens only at create method. Other methods insert and update work correctly and format a table name with a single prefix.

Information

Detail Code Config example:

new Medoo([
            // [required]
            'type' => 'mysql',
            'socket' => '/var/run/mysqld/mysqld.sock',
            'database' => 'c1hbm',
            'username' => 'c1hbm',
            'password' => 'xxxx',

            // [optional]
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_general_ci',

            // [optional] Table prefix, all table names will be prefixed as PREFIX_table.
            'prefix' => 'HBM_',

            // [optional] Enable logging, it is disabled by default for better performance.
            'logging' => true,

            // [optional]
            // Error mode
            // Error handling strategies when error is occurred.
            // PDO::ERRMODE_SILENT (default) | PDO::ERRMODE_WARNING | PDO::ERRMODE_EXCEPTION
            // Read more from https://www.php.net/manual/en/pdo.error-handling.php.
            'error' => PDO::ERRMODE_SILENT,
        ]);

After I call

$db->create('products',[
            "id" => [
                "INT",
                "DEFAULT NULL",
                "AUTO_INCREMENT",
                "PRIMARY KEY",
            ],
            "product_id" => [
                "VARCHAR(30)",
                "NOT NULL",
                "COMMENT 'Original product ID'",
            ],
            "name" => [
                "VARCHAR(255)",
                "NOT NULL",
                "COMMENT 'Product name'",
            ],
        ]);

In phpmyadmin I see a table named HBM_HBM_products.

Expected output I expect to see a table named HBM_products. When I call commands like insert or update - they correctly refer to HBM_products table and as a result lead to error:

42S02
Table 'c1hbm.HBM_products' doesn't exist 
catfan commented 3 years ago

Thanks for the feedback. It's fixed on 7d9ac11.