Redbean: Getting Started (i)

Source: Internet
Author: User

<?PHPrequire_once' Rb.php '; $tableName= "link"; //Link DatabaseR::setup ("Mysql:host=localhost;dbname=hwibs_model", "Root", "" "); //Create a table (also referred to as instantiating a table)    $handler= R::d ispense ($tableName); ##################################### Add #####################################        /*ibid. [Instantiate multiple tables simultaneously] list ($handler _1, $handler _2) = R::d ispenseall ("test_1,test_2"); */    //Object mode assignment to Field//:: Note that if the field does not exist, the corresponding field is automatically added after the store method, and the corresponding field type for the field is automatically set according to the field value    $handler->name = "haha"; $handler->url = "Isxiugai"; $handler->plushtime = Time()-5000; //If you have an underlined field name, you can use the Hump method to name it, and it will be automatically converted to an underscore    $handler->ismyname =false;//= is_my_name//execution, this static method returns the increment ID value (single) after adding success    $inser _id= R::store ($handler); ##################################### Query ####################################//Gets the record handle (parameter 1 is the table name, Parameter 2 is the ID value), The return value is the object collection//If the ID does not exist, then return 0//Note that this gets to the handle that can be used for the delete operation    $bean= R::load ($tableName, 4);//get a single    $beans= R::loadall ($tableName,Array(1,2,3,4));//Get multiple    ##################################### Update #####################################//1. Note that the only difference between the changes and the add is the ID, if the ID    is not empty, it is modified, otherwise it is added! 2. If the ID does not exist, it will neither be added nor modified! Therefore, it is generally necessary to use load to determine whether there is a prior modification.        foreach($beans  as $k=$v){        $beans[$k]->url =Rand(100,5555);//test [Loop assigns a random number of URLs in each record object]} R:: StoreAll ($beans);//Perform modifications            ##################################### Delete #####################################//delete single:: Success or failure is return null    Var_dump(R::trash (R::load ($tableName, 1))); //Delete multiple:: If there is a non-existent, it will only delete the existing, success or failure is returned null    Var_dump(R::trashall (R::loadall ($tableName,Array(117,118)))); ##################################### Other #####################################//clears all data in the table:: Equivalent to truncate,    Because the self-increment pointer resets the//r::wipe ($tableName);    Delete all the tables in the database, [no language function, to this hair]//var_dump (R::nuke ()); Close linkR::close ();?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.