Questions tagged [redbean]

RedBeanPHP is an open-source ORM library written for PHP.

About

RedBeanPHP is open-source object-relational mapping software written in PHP.

The main proponent of this software is the configuration-less way that the software will create the tables and columns on-the-fly as you run your PHP code. It does this by working in a 'fluid' mode where the software will check for requested columns when the code is running and create them if they do not exist, it will even broaden the type of a column, for example if your application changes from storing numbers to text.

Once you are happy with your structure and do not want the data structure to change any further you can invoke the freeze command:

R::freeze( true ); //will freeze redbeanphp

This will lock your schema and prevent changes.

Setup & Using Redbean

RedBeanPHP is packaged up into a single php file (rb.php approx 285KB) so that a single include statement and you're ready to go:

require 'rb.php';

Working with Data

An example of CRUD operations with RedBean:

$post = R::dispense('post');
$post->text = 'Hello World';

$id = R::store($post);       //Create or Update
$post = R::load('post',$id); //Retrieve
R::trash($post);             //Delete

Database Compatibility

RedBean works with many database engines in fluid and frozen mode:

MySQL 5 and higher

SQLite 3.6.19 and higher

PostgreSQL 8 and higher

CUBRID (since 3.2)

Oracle* (since 3.3, read note)

278 questions
86
votes
9 answers

Using json_encode on objects in PHP (regardless of scope)

I'm trying to output lists of objects as json and would like to know if there's a way to make objects usable to json_encode? The code I've got looks something like $related = $user->getRelatedUsers(); echo json_encode($related); Right now, I'm…
A. Rager
  • 1,950
  • 2
  • 15
  • 16
21
votes
4 answers

RedBean ORM performance

I would like to know whether Redbean ORM can be used for performance oriented scenarios like social networking web apps or no and is it stable even if thousands of data are pulled by multiple users at same time. Also I'd like to know whether Redbean…
Jaison Justus
  • 2,753
  • 8
  • 47
  • 65
21
votes
1 answer

Can I export a Sqlite db using RedBean PHP ORM and Import to MySQL?

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…
Armstrongest
  • 15,181
  • 13
  • 67
  • 106
15
votes
2 answers

Process for Upgrading from RedBean 3.5 to RedBean 4

I am currently using RedBean version 3.5. I think I would like to move to the latest version of RedBean, version 4. I have found no documentation about upgrade process, other than an indication it is not straightforward. My questions are: Is my…
Jay Haase
  • 1,979
  • 1
  • 16
  • 36
8
votes
2 answers

PHP Red Bean ORM Performance issue

I am making a WebService in php which my website will use to query for information with Ajax calls. At first i just did it the standard way with the built in php mysql lib, and wrote all the query's manually and made the whole data model in MySQL…
furier
  • 1,934
  • 1
  • 21
  • 39
7
votes
2 answers

Does RedBean need a "id" primary key?

If you use RedBean ORM, do you need to add a primary key named "id" to every table in your database? In my db I have a few tables that have primary keys pairs of 2 or 3 fields, or primary keys with other names than "id" (yes, I could change the name…
Alex
  • 66,732
  • 177
  • 439
  • 641
7
votes
4 answers

Redbean O/RM store "date" as varchar(255)?

From this code: $toolbox = RedBean_Setup::kickstartDev("mysql:*****************"); $r = $toolbox->getRedBean(); $test = $r->dispense("test"); $test->nom = 'Test #1'; $test->date = '2010-07-08'; $test->date_deux = '08/07/2010'; $test->num = 5; $id…
Sirber
  • 3,358
  • 5
  • 25
  • 32
6
votes
1 answer

Retrieving only some fields in RedBean

I'm using RedBean ORM to write some code and I was wondering if i can load/retrive only some fields from db table. I know there is a load method but it gives whole table as bean. I wish to get only some fields? Heh, when i wrote it, I started…
f1ames
  • 1,714
  • 1
  • 19
  • 36
6
votes
1 answer

How to configure PHPStan to avoid false positives caused by specific classes and/or magic methods?

While using PHP RedBean on a project, PHPStan reports problems like this one: 87 Access to an undefined property RedBeanPHP\OODBBean::$token. This is happening because RedBean's OODBBean class uses magic methods to logically bind class…
Diogo Melo
  • 1,735
  • 3
  • 20
  • 29
6
votes
1 answer

Silex / Symfony2 Remember Me Authentication User Interface RedBean Wrapper

I've been trying to use RedBean ORM (http://redbeanphp.com) to implement UserInterface and UserProviderInterface of the Silex Security Provider Package. Because of the way the RedBean ORM handles functions for its objects, I've needed to wrap the…
christian
  • 2,279
  • 4
  • 31
  • 42
6
votes
1 answer

speed up php::PDO->__construct

i used webgrind and xdebug to messure my site performance. 85% of page loading time is taken for the function php::PDO->__construct (about 1 second) ... this is unacceptable. can i somehow optimize this function? (caching, mysql configuration…
Benjamin Eckstein
  • 884
  • 2
  • 9
  • 19
6
votes
4 answers

How to bulk insert with RedBeanPhp?

I was hoping for an example on how to bulk insert new "beans" in readbeanphp without looping over each instance. It shows an example creating and saving a beans here: http://redbeanphp.com/manual/create_a_bean It makes mention of storeAll($beans)…
Chris
  • 764
  • 1
  • 10
  • 24
6
votes
2 answers

Database design for posts and comments

If one post has many comments, and the comments are essentially the same as posts (e.g. they have a title, pictures and audio etc.) should I create two tables or just one? For example, if I only use one table I can have a parent_id column, so If…
john mossel
  • 2,158
  • 5
  • 24
  • 39
5
votes
1 answer

PHP RedBean store bean if not exist one

I am a little confused. I actively use PHP RedBean as ORM within my direct mail service and I run into curious situation - I have a table with unique key constraint (i.e. subscriber_id, delivery_id) and two scripts that is writing data into this…
Ivan Velichko
  • 6,348
  • 6
  • 44
  • 90
5
votes
1 answer

Redbean, Multiple many-to-many using same object

Many-to-many mappings are easy to use in redbean with simple scenarios. But how do you do multiple many-to-many mapping between the very same object? Example: What I want to acomplish is in structure very similar to the twitter/instagram setup of…
Petter Nordlander
  • 22,053
  • 5
  • 50
  • 84
1
2 3
18 19