I have a simple web app that I've been building using redbean
PHP which has a really simple structure with three bean types:
areas buildings persons
All relationships are exclusive 1:Many. So, a Person
belongs to only 1 Building
, and a Building
belongs to 1 Area
.
Area
BuildingList
PersonList
Currently, I have been developing it using Sqlite3
for ease of development, but I want to move the data to mySQL
. I have a lot of data that I've already added.
Is there an easy way to use RedBean to Export ALL beans to the new MySql Database?
I know I can search for a sqlite
-> MySQL
/MariaDB
converter, but I also potentially want to be able to use this in reverse to make migrating the site super easy to move/backup/change DBs.
What I've tried below:
R::setup('sqlite:/' . __DIR__ . '/data/database.db');
R::addDatabase('mysql', $MySqlConn );
$old_datas = R::findAll( 'area' );
R::selectDatabase( 'mysql' );
foreach ($old_datas as $bean) {
$new_area = R::dispense('area');
$new_area->importFrom( $bean );
$id = R::store( $new_area );
var_dump( $new_area ); // shows new data
}
var_dump( R::findAll( 'area' ) ); // returns empty array
I'll preface this by saying that I've not personally tried to do so, but since you can dump an entire database via the sqlite3 console, then my first approach would be to do so, and then try importing that file into MySQL.
Dumping a sqlite3 database from the sqlite console:
sqlite> output database_dump.sql
sqlite> .dump
sqlite> .quit
Importing a .sql file into MySQL (as described here):
mysql> use DATABASE_NAME
mysql> source path/to/file.sql
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With