0

Is there a way to manually set the ID of a new bean using RedBean PHP? I'm storing cached data from an API which generates the ID of each row and would just like to use that ID for simplicity.

I've read other threads that say to simply create a new column (row_id) or something, but I'd like to just use the unique generated ID as the ID.

rtruszk
3,92213 gold badges40 silver badges54 bronze badges
asked Jul 24, 2015 at 11:42

1 Answer 1

0

As per MySQL doc

No value was specified for the AUTO_INCREMENT column, so MySQL assigned sequence numbers automatically. You can also explicitly assign 0 to the column to generate sequence numbers. If the column is declared NOT NULL, it is also possible to assign NULL to the column to generate sequence numbers. When you insert any other value into an AUTO_INCREMENT column, the column is set to that value and the sequence is reset so that the next automatically generated value follows sequentially from the largest column value.

If that's true, in RedBean you can do something like

$post = R::dispense('post');
$post->id = 234;
R::store($post);

I haven't tested this since i keep auto-incremented column set to integer default to 0 which automatically increments.

answered Jun 13, 2016 at 12:46
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.