Medoo icon indicating copy to clipboard operation
Medoo copied to clipboard

Import from SQL file - feature request

Open blessedjasonmwanza opened this issue 3 years ago β€’ 4 comments

Information

  • Version of Medoo: 2.1.2
  • Type of Database (MySQL, MSSQL, SQLite...):
  • System (Liunx\Windows\Mac):

Description

This is a feature request; When you have time, may you kindly add the ability for us to import an SQL file directly into a database?

Detail Code example

$file_location = 'dir/file.sql';
$db_instance->import_sql($file_location);
//or
$db_instance->import_raw($file_location);

Response

Can return true, false or add the error message into the $db->error var

blessedjasonmwanza avatar Aug 21 '21 17:08 blessedjasonmwanza

With the experience of importing the database file, the better way to do this is to use the SQL command line or other database management tools to ensure the correct result.

catfan avatar Aug 22 '21 05:08 catfan

Hey @catfan πŸ€“ ... I was thinking about this and experimented with something that works.

//First, we load the db file into a variable
$db_sql_file = file_get_contents("db_file.sql");
//then we run query on it to perform whatever instructions are in the SQL file against the database instance we're connected toπŸ˜„ 
$db_instance->query($db_sql_file);

Is this something that can be improved on? You may share your opinion or ideas whenever time allows.

HappyCoding πŸ‘¨πŸ½β€πŸ’»

blessedjasonmwanza avatar Oct 18 '21 22:10 blessedjasonmwanza

@blessedjasonmwanza Yes, it can simply work in some cases. However, the result is not guaranteed if with a different setting, database version, platform, or others.

catfan avatar Oct 19 '21 11:10 catfan

@blessedjasonmwanza Yes, it can simply work in some cases. However, the result is not guaranteed if with a different setting, database version, platform, or others.

Oh - I see, πŸ€” ... Makes a lot of sense πŸ€“ . Thank you.

blessedjasonmwanza avatar Oct 19 '21 11:10 blessedjasonmwanza