I am currently working on some php code using redbeanphp that should store data into database tables using four different R::store
functions, but only the first two work, and I don't know why the other two aren't working because I made no spelling mistakes and if I try to do it with R::storeAll
it also only works for the first two objects.
My code:
require "rb.php";
R::setup('mysql:host=localhost;dbname=building_framework', 'root', '');
// Books table
$books1 = R::dispense('books');
$books1->title = "Wonders of the world";
$books1->author_id = "1";
$books1->publisher_id = "1";
$books2 = R::dispense('books');
$books2->title = "Math for dummy's";
$books2->author_id = "1";
$books2->publisher_id = "1";
// Author table
$author = R::dispense('author');
$author->id = "1";
$author->author = "Francesco Boccia";
// Publisher table
$publisher = R::dispense('publisher');
$publisher->id = "1";
$publisher->publisher = "Metro Books";
$store1 = R::store($books1);
$store2 = R::store($books2);
$store3 = R::store($author);
$store4 = R::store($publisher);
echo $store1;
echo $store2;
echo $store3;
echo $store4;
When I execute it, all the tables are getting made, but only in the books
table, data is stored and not in the other two. Can someone please help me fixing this?
I know my mistake. I added an id
for author
and for publisher
but the id gets added by redbean itself, so there was no need for that.