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