Last active
August 29, 2015 14:10
-
-
Save ihsanberahim/934b22df6752cf6163c8 to your computer and use it in GitHub Desktop.
Make RedBean Works on Custom Table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#RedBean needs the 'id' column. | |
ALTER TABLE `table_name` ADD `id` INT UNSIGNED NULL DEFAULT '1'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
RedBean need 'id' column but | |
your table use profile_id. | |
So, we need to sync it | |
*/ | |
//Register User | |
$bean = R::dispense( "profile" ); | |
$bean->profile_username=$profile_username; | |
$bean->profile_password=$profile_password; | |
$bean->token=null; | |
R::store($bean); | |
//Fix Bean ID | |
$bean_id = R::getCell("SELECT MAX(profile_id) AS profile_id FROM profile"); | |
R::exec( "UPDATE profile SET id=:id WHERE profile_id=:id", | |
[ | |
':id' => $bean_id | |
]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
R::setup(); | |
R::setStrictTyping(false); | |
R::ext('xdispense', function($type){ | |
return R::getRedBean()->dispense($type); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment