Dynamo

License

Copyright © 2011 by Joel Dare

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Quick Reference

DynamoColTableQuery($query, $columns)

Executes a query and returns an HTML table that is $columns columns wide containing the results. The $query string must return a single column of data from the database.

$query = "SELECT concat(city, ', ', state) FROM cities";

$result = DynamoColQuery($query, 3);

echo $result;

DynamoCsvQuery($query, [$header], [$separator])

Executes the query and returns CSV (Comma Seperated Value) output containing the results. If you want column headings set $header to true. To use a different separator set the $separator value to something other than ',' such as '|' or "\t".

$query = "SELECT firstName, lastName FROM regData WHERE id > 0";

$result = DynamoCsvQuery($query);

echo $result;

DynamoEditForm($query,$page, [$class])

Selects a row of data using the $query string, and returns an HTML form that allows the user to edit the fields returned by the $query string. The $query string must return a single row of data. When the user clicks the SUBMIT button on the generated form, it will POST field data to $page. The page that receieves the post from the editForm() call should call DynamoExecRawQuery() with an appropriate update query. The optional $class value can be included to write the output with a specific CSS class name. The default class is "dynamo".

$query = "SELECT firstName, lastName FROM cust WHERE id = 1234";

$result = DynamoEditForm($query);

echo $result;

DynamoOutputQuery($query)

Splits the string $query into multiple parts, executes the individual queries one at a time, and returns the unformatted results. Multiple queries can be included in the $query string. Multiple queries must be seperated by a semicolon.

$query = "SELECT '', '', firstname, '', '' FROM regData WHERE id > 0";

$result = DynamoOutputQuery($query);

echo $result;

DynamoRawQuery($query)

Executes the raw $query string and returns the results, if any. This function is usually used when output is not needed. Often it is used to insert a new record into the database or to update an existing record. It can be followed by an editForm() function in order to edit the newly inserted data.

$query = "INSERT INTO blog (date, subject, body) VALUES ('$date('Y-m-d')', '', '')";

$result = DynamoRawQuery($query);

$query = "SELECT date, subject, body FROM blog WHERE id = mysql_insert_id()";

editForm($query,'apply.html');

DynamoTableQuery($query, [$class], [$header])

Executes the query and returns an HTML table containing the results. Specify a $class variable to have the output be in a specific CSS class. The default class is "dynamo". If you want bolded column headings set $header to true.

$query = "SELECT firstName, lastName FROM regData WHERE id > 0";

$result = DynamoTableQuery($query);

echo $result;

DynamoVarQuery($query)

Executes the $query string and returns the resulting data as an array. The $query string must return a single row of data.

$query = "SELECT firstName, lastName FROM cust WHERE id = 1234";

$queryVal = DynamoVarQuery($query);

echo 'First Name: ' . $queryVal['firstName']; echo 'Last Name: ' . $queryVal['lastName'];

DynamoVertTableQuery($query)

Executes the query and returns a vertical HTML table containing the result. The column names are in the left column and the values are in the right column of the table. The query must return only a single result.

$query = "SELECT firstName, lastName FROM regData WHERE id = 123";

$htmlTable = DynamoVertTableQuery($query);

echo $htmlTable;