Redbean: Getting Started (iii)-Exec and Query and Converttobeans

Source: Internet
Author: User
Tags dsn

<?PHP//introducing the RB entry file    include_once' Rb.php '; //define DSN and related data    $dsn= ' Mysql:host=localhost;dbname=hwibs_model '; $user= ' Root '; $pass= ' '; $table= ' link '; //Link DatabaseR::setup ($dsn,$user,$pass); //Linked Data TablesR::d ispense ($table); //exec:: Execute an SQL statement directly [do not need a linked table to use] [parameter 2 binding function as find, no longer repeat]//note, here is generally applicable to adding and removing changes, the query will only return the number of records, and will not return the record itself [if you want to query and return the record itself, Need to use GetAll]    $result= R::exec("SELECT * FROM Link"); //GetALL:: The difference between this function and the load or find is that it only returns the data itself and returns it in a multidimensional array [even if you TM is a record]    $result= R::getall ("SELECT * from link where id =?",Array(4));//small use of the binding function//getrow:: This function is the same as the above getall, the difference he just return a single line, similar to FindOne, the difference is that the single-dimension array is returned    $result= R::getrow ("Select URL from link"); //Getcol:: Legend gets a single column of data [that is, one field]//1. Note that if the field collection is * or multiple columns, the first column is taken anyway, so this function is only available when you need to take the value of a field//2. Of course, it can take multiple rows, but only one column     $result= R::getcol ("Select URL from link"); //Getcell:: This is the same as the above, the difference is that the second, it can only take the first row of the field value of the column [for accurate data acquisition use]    $result= R::getcell (' Select URL from link '); //Getassoc:: This method is interesting; it only supports data return for two field columns, the first field value as the key, and the second field value as the value to return//1. The return data is a one-dimensional array    $result= R::getassoc ("Select Url,name from Link"); //Getassocrow:: I just can't figure out what's different about this function and the TM GetAll .    $result= R::getassocrow ("SELECT * from link where id = 3"); //Converttobeans: This is a function that will use the data found in addition to the load or Find method and convert it to Redbaan's own object format//1. At least as far as the current understanding is concerned, it can be used to delete an operation//2. Parameter 2 is at least a one-dimensional array, and just returning a value like Getcell cannot be converted.    $beans= R::converttobeans ($table,$result); Print_r($beans);//Output?>

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.