How to start with readbeanphp

1.Download redbean.php

Lets make a project

dbconnect.php

define(‘MODE’,’PRODUCTION’);

require “rb.php”;

R::setup(‘mysql:host=localhost;dbname=mydatabase’, ‘user’,’password’);

if(MODE ==’DEVELOPMENT’){

R::debug(‘tree’);

 

}

else{

R::debug(false);

R::freeze( true ); // it wont made any table or adjustment by its own

}

/*

Change your database information

to know more about debugging –  http://redbeanphp.com/debugging

http://redbeanphp.com/manual3_0/freeze

*/

create.php

include “dbconnect.php”;

$book = R::dispense( ‘book’ );   //table name book
$book->title = ‘Learn to Program’; //fieldname =value
$book->rating = 10;
$id = R::store( $book );  //save it will return the id of the inserted data.

list.php

include “dbconnect.php”;

$books = R::findAll( ‘book’ , ‘ ORDER BY id DESC LIMIT 10 ‘ ); //return array

foreach($books as $book){

print(“$book[id] ========== $book[title]”);

}

/*

http://redbeanphp.com/manual3_0/queries

http://redbeanphp.com/finding

*/

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s