Skip to content

Instantly share code, notes, and snippets.

@ihsanberahim
Last active August 29, 2015 14:10
Show Gist options
  • Save ihsanberahim/934b22df6752cf6163c8 to your computer and use it in GitHub Desktop.
Save ihsanberahim/934b22df6752cf6163c8 to your computer and use it in GitHub Desktop.
Make RedBean Works on Custom Table
#RedBean needs the 'id' column.
ALTER TABLE `table_name` ADD `id` INT UNSIGNED NULL DEFAULT '1';
<?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
]);
<?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