P
P
part_os2020-09-05 15:05:19
MariaDB
part_os, 2020-09-05 15:05:19

How to throw the scheme from the dump into the created database?

Tell me how to fill the newly created database with a dump, or is there some other way?
there is a file with a dump, I create an empty database and I want to load the scheme. here is my way:

$dbName = 'ec'.$tenantCreate->id;
        $query = sprintf(
            "CREATE DATABASE IF NOT EXISTS %s CHARACTER SET %s COLLATE %s;",
            $dbName,
            $charset,
            $collation
        );

        $result = $connection->statement($query);

        if (!$result) {
            throw new \Exception('Не создана база данных для аккаунта ' . $tenantCreate->id);
        }

        $query = sprintf(
            "USE %s; SOURCE %s;",
            $dbName,
            __DIR__ . '/../../../../dump_scheme.sql'
        );

        $result = $connection->statement($query);


SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SOURCE /var/www/app/Tenant/Infrastructure/Services/../../../../dump_sch' at line 1 (SQL: USE ec32; SOURCE /var/www/app/Tenant/Infrastructure/Services/../../../../dump_scheme.sql;)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
part_os, 2020-09-05
@part_os

suddenly someone will come in handy, did like this.
$sql_dump = File::get(__DIR__ . '/../../../../dump_scheme.sql');
$result = $connection->getPdo()->exec($sql_dump);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question