Skip to content

Working with dave mysql functions

evantahler edited this page Apr 9, 2011 · 8 revisions

_DAVE functions

Globally available to the API, are the DAVE database functions, _DELETE(), _ADD(), _EDIT(), _VIEW(). These methods are an easy-to-use abstraction layer for mySQL. These functions are defined within DAVE.php

_ADD

_ADD($Table, $VARS = null)

The add function will attempt to add a new row to the database table $Table. If $VARS is not provided, $PRAMS will be used as a default. This means that you can simply add a user to your users table with just _add("Users");. Validations are preformed for you automatically and the response will contain feedback such as "ScreenName needed" assuming ScreenName is a non-null column in the database.

_ADD will return an array with the first value being true or false based on the success of the insert.

  • _ADD will return the $TABLES[$Table]['META']['KEY'] (Primary key) of the new row upon success as element 1 of the returned array
  • _ADD will return a human_readable error message upon failure as element 1 of the returned array

_EDIT

_EDIT($Table, $VARS = null)

This function will update an existing row within a table. If $VARS is not provided, $PRAMS will be used as a default. You need to provide at least one variable which is unique in the table to define the table. If you are changing one of the unique variables (perhaps ScreenName), you will need to provide the $TABLES[$Table]['META']['KEY'] (Primary key).

_EDIT will return an array with the first value being true or false based on the success of the edit.

  • _EDIT will return an array of all the row's updated details upon success as element 0 of the returned array
  • _EDIT will return a human_readable error message upon failure as element 0 of the returned array

_VIEW

_VIEW($Table, $VARS = null, $Settings = null )

This function return a collection of records that match requested details. If $VARS is not provided, $PRAMS will be used as a default.

$SETTING is an array with the following options:

  • $Settings["select"] : If set, will overrite the normal "Select * from $TAble" part of the SQL select statement, and will be filled in like: "SELECT $Settings["select"] ... "
  • $Settings["join"] : If set, will be used to join in other tables, and will be filled in per " ... JOIN $Settings["join"] ... "
  • $Settings["where_additions"] : if set, will modify the WHERE statement per: " ... AND $Settings["where_additions"]"
  • $Settings["sort"] : if set, will be included after the end of the where clause, freeform: " ... $Settings["sort"] ... "
  • $Settings["UpperLimit"] : will be used to augment the LIMIT per: " ... LIMIT $Settings["LowerLimit"],$Settings["UpperLimit"] ". Will be set to defaults per below.
  • $Settings["LowerLimit"] : will be used to augment the LIMIT per: " ... LIMIT $Settings["LowerLimit"],$Settings["UpperLimit"] ". Will be set to defaults per below.
  • $Settings["SQL_Override"] : true/false. If true, SELECT statement will not be required to have at least one unique column entry in the search.

$VARS / $PARAMS may be null, but most table SELECTS will require that one of the unique columns be provided. This can be turned off by setting $Settings['SQL_override'] = true;

The Global $UpperLimit and $LowerLimit (unless they are overwritten in $Settings) values are used to limit the SQL response directly with the mySQL LIMIT keyword. If UpperLimit is null, it will default to 100. LowerLimit will default to 0.

_VIEW will return an array with the first value being true or false based on the success of the SELECT.

  • _VIEW will return an array containing the attributes of every row returned by the SELECT.
  • _VIEW will return a human_readable error message upon failure as element 0 of the returned array

_DELETE

_DELETE($Table, $VARS = null)

This function will remove a row. If $VARS is not provided, $PRAMS will be used as a default. You need to provide at least one variable which is unique in the table to define the table. This will ensure that _DELETE will only ever delete, at most, one record.

_DELETE will return an array with the first value being true or false based on the success of the delete.

  • _DELETE will return true upon success as element 1 of the returned array
  • _DELETE will return a human_readable status message explaining the status of the connection to the database failure as element 1 of the returned array
Something went wrong with that request. Please try again.