RedBeanPHP Class Reference Cheat Sheet by Richard Holloway (richardjh) via cheatography.com/478/cs/347/

About RedBeanPHP ORM Class Reference pt2 Class Reference pt3

Easy ORM for PHP and MySQL, PostgreSQL and findAndExport( $type, $=null, $value=array() ) isoDate( $time=null ) many other database systems. Finds a bean using a type and a where clause Simple convenience function, returns ISO date Use the simplicity of NoSQL with the power of SQL. (SQL). As with most Query tools in RedBean you formatted representation of $time

can provide values to be inserted in the SQL isoDateTime( $time=null ) http://redbeanphp.com/ statement by populating the value array parameter; Simple convenience function, returns ISO date time you can either use the question mark notation or formatted representation of $time. Class Reference pt1 the slot-notation (:keyname). The variation also load( $type, $id ) exports the beans (i.e. it returns arrays). addDatabase ( $key, $dsn, $user=null, $pass=null, Loads the bean with the given type and id and findLast( $type, $sql=null, $values=array() ) $frozen=false ) returns it. Finds a bean using a type and a where clause Adds a database to the facade, afterwards you can log( $filename ) (SQL). As with most Query tools in RedBean you select the database using selectDatabase($key). Activates TimeLine Schema Alteration monitoring can provide values to be inserted in the SQL addTags ( $bean, $tagList ) and Query logging. statement by populating the value array parameter; Part of RedBeanPHP Tagging API. Adds tags to a you can either use the question mark notation or nuke() bean. If $tagList is a comma separated list of tags the slot-notation (:keyname). This variation returns Nukes the entire database all tags will be associated with the bean. You may the last bean only. query( $method, $sql, $values ) also pass an array instead of a string. findOne( $type, $sql=null, $values=array() ) Internal Query function, executes the desired query. areRelated( $bean1, $bean2 ) Finds a bean using a type and a where clause Used by all facade query functions. This keeps Checks whether a pair of beans is related N-M. This (SQL). As with most Query tools in RedBean you things DRY. function does not check whether the beans are can provide values to be inserted in the SQL related( $bean, $type, $sql=null, $values=array() ) related in N:1 way. statement by populating the value array parameter; Returns all the beans associated with $bean. This associate( $bean1, $bean2, $extra=null ) you can either use the question mark notation or method will return an array containing all the beans Associates two Beans. This method will associate the slot-notation (:keyname). This variation returns that have been associated once with the associ two beans with eachother. You can then get one of the first bean only. ate() function and are still associated with the bean the beans by using the related() function and findOrDispense( $type, $sql, $values ) specified. providing the other bean. Convenience method. Tries to find beans of a relatedOne( $bean, $type, $sql=null, $values=array() ) batch( $type, $ids ) certain type, if no beans are found, it dispenses a Returns only single associated bean. Returns an array of beans. Pass a type and a series bean of that type. rollback() of ids and this method will bring you the corres freeze( $tr=true ) Facade Convience method for adapter transaction pondig beans. Toggles fluid or frozen mode. In fluid mode the system. Rolls back a transaction. begin() database structure is adjusted to accomodate your selectDatabase( $key ) Facade Convience method for adapter transaction objects. In frozen mode this is not the case. Selects a different database for the Facade to work system. Begins a transaction. gatherLabels( $beans ) with. clearRelations( $bean, $type ) Gathers labels from beans. This function loops setup( $dsn=null, $username=null, $password=null ) Clears all associated beans. Breaks all many-to- through the beans, collects the values of the name Kickstarts redbean for you. This method should be many associations of a bean and a specified type. properties of each individual bean and stores the called before you start using RedBean. The Setup() names in a new array. The array then gets sorted close() method can be called without any arguments, in using the default sort function of PHP (sort). Closes the database connection. this case it will try to create a SQLite database in commit() genSlots( $array ) /tmp called red.db (this only works on UNIX-like Facade Convience method for adapter transaction Generates question mark slots for an array of systems). values. system. Commits a transaction. store( $bean ) configureFacadeWithToolbox( $tb ) getAll( $sql, $values=array() ) Stores a RedBean OODB Bean and returns the ID. Convenience function to execute Queries directly. Configures the facade, want to have a new Writer? storeAll( $beans ) Executes SQL. A new Object Database or a new Adapter and you Short hand function to store a set of beans at once, want it on-the-fly? Use this method to hot-swap getAssoc( $sql, $values=array() ) IDs will be returned as an array. For information your facade with a new toolbox. Convenience function to execute Queries directly. please consult the R::store() function. A loop saver. Executes SQL. Results will be returned as an convertToBeans( $type, $rows ) swap( $beans, $property ) associative array. The first column in the select Converts a series of rows to beans. Given an array of two beans and a property, this clause will be used for the keys in this array and the count( $beanType ) method swaps the value of the property. This is second column will be used for the values. If only Counts beans handy if you need to swap the priority or orderNo of one column is selected in the query, both key and an item (i.e. bug-tracking, page order). debug( $tr=true ) value of the array will have the value of this field for Toggles DEBUG mode. In Debug mode all SQL that each row. tag( $bean, $tagList=null ) happens under the hood will be printed to the Part of RedBeanPHP Tagging API. Tags a bean or getCell( $sql, $values=array() ) screen. returns tags associated with a bean. If $tagList is Convenience function to execute Queries directly. null or omitted this method will return a comma dependencies( $dep ) Executes SQL. separated list of tags associated with the bean Sets a list of dependencies. A dependency list getCol( $sql, $values=array() ) provided. If $tagList is a comma separated list contains an entry for each dependent bean. A Convenience function to execute Queries directly. (string) of tags all tags will be associated with the dependent bean will be removed if the relation with Executes SQL. bean. You may also pass an array instead of a one of the dependencies gets broken. getColumns( $table ) string. dispense( $type, $num ) Returns a list of columns. Format of this array: tagged( $beanType, $tagList ) Dispenses a new RedBean OODB Bean for use array( fieldname => type ) Note that this method Part of RedBeanPHP Tagging API. Returns all array( fieldname => type ) Note that this method Part of RedBeanPHP Tagging API. Returns all with the rest of the methods. only works in fluid mode because it might be quite beans that have been tagged with one of the tags dispenseLabels( $type, $labels ) heavy on production servers! given. A label is a bean with only an id, type and name getRow( $sql, $values=array() ) trash( $bean ) property. This function will dispense beans for all Convenience function to execute Queries directly. Deletes the specified bean. entries in the array. The values of the array will be Executes SQL. assigned to the name property of each individual trashAll( $beans ) bean. getVersion() Short hand function to trash a set of beans at once. Get version For information please consult the R::trash() dup( $bean, $trail, $pid=false ) function. A loop saver. Makes a copy of a bean. This method makes a graph( $array, $filterEmpty=false ) deep copy of the bean. facade method for Cooker Graph. unassociate( $bean1, $bean2, fast=false ) Breaks the association between two beans. This exec( $sql, $values=array() ) hasTags( $bean, $tags, $all=false ) functions breaks the association between a pair of Convenience function to execute Queries directly. Part of RedBeanPHP Tagging API. Tests whether a beans. After calling this functions the beans will no Executes SQL. bean has been associated with one ore more of the listed tags. If the third parameter is TRUE this longer be associated with eachother. Calling exportAll( $beans ) method will return TRUE only if all tags that have related() with either one of the beans will no longer Exports a collection of beans. Handy for XML/JSON been specified are indeed associated with the return the other bean. exports with a Javascript framework like Dojo or given bean, otherwise FALSE. If the third parameter unrelated( $bean, $type, $sql=null, $values=array() ) ExtJS. is FALSE this method will return TRUE if one of the The opposite of related(). Returns all the beans that find( $type, $sql=null, $values=array() ) tags matches, FALSE if none match. are not associated with the bean provided. Finds a bean using a type and a where clause untag( $bean, $tagList ) (SQL). As with most Query tools in RedBean you Part of RedBeanPHP Tagging API. Removes all can provide values to be inserted in the SQL sepcified tags from the bean. The tags specified in statement by populating the value array parameter; the second parameter will no longer be associated you can either use the question mark notation or with the bean. the slot-notation (:keyname). wipe( $beanType ) findAll( $type, $sql=null, $values=array() ) Wipes all beans of type $beanType. Finds a bean using a type and a where clause (SQL). As with most Query tools in RedBean you can provide values to be inserted in the SQL Class Reference: See Also statement by populating the value array parameter; Converted from the comments in the source code. you can either use the question mark notation or See http://www.redbeanphp.com/api/d9/daa/class_re the slot-notation (:keyname). The findAll() method d_bean___facade.html for more details. differs from the find() method in that it does not assume a WHERE-clause.

Cheatographer Cheat Sheet Sponsor

Richard Holloway (richardjh) This cheat sheet was published on 16th April, 2012 FeedbackFair, increase your conversion rate today! cheatography.com/richardjh/ and was last updated on 16th April, 2012. Try it free! richardjh.org http://www.FeedbackFair.com