| [ Index ] |
PHP Cross Reference of Crawler |
[Source view] [Print] [Project Stats]
Custom library of bare-bones MYSQL query and minipulation functions to peform basic SELECT, INSERT, and UPDATE queries. Library provides a VERY lightweight wrapper to to sanitize data and run simple MySQL queries. Accepts associative arrays for both query and data, and return associative arrays with results.
| Author: | Benjamin J. Balter <ben@balter.com> |
| Version: | 1.1 |
| File Size: | 291 lines (9 kb) |
| Included or required: | 4 times |
| Referenced: | 0 times |
| Includes or requires: | 0 files |
| mysql_array($result,$assoc = TRUE) X-Ref |
| Function to generate a multi-dimensional associative array from a MySQL resource. Example Usage, given the table below Players -------------------- ID Name Position -------------------- 1 Kevin 1B 2 Tom LF 3 Sally SS The Command "mysql_array(mysql_select('players'))" Would return the following array <code> array( [1] => array( ['ID'] => 1, ['Name'] => "Kevin", ['Position'] => '1B' ), [2] => array( ['ID'] => 2, ['Name'] => "Tom", ['Position'] => 'LF' ), [3] => array( ['ID'] => 3, ['Name'] => "Sally", ['Position'] => 'SS' ) ) param: resource $result MySQL resource object (either output of mysql_query($sql) or mysql_select('table',$query)) param: bool $assoc makes Associate array optional (added 1.1) return: array Multi-dimensional Associative array keyed to first field in table, returns empty array if no results |
| mysql_row_array($result) X-Ref |
| Returns an array of a single MySQL result row. Similar to mysql_fetch_assoc exccept it strips slashes, returns an empty array (rather than an error) if resource is bad or no results are found param: resource $result MySQL resource object (either output of mysql_query($sql) or mysql_select('table',$query)) return: array Associative array of row, returns empty array if no results |
| mysql_insert($table, $data) X-Ref |
| Generates SQL query, sanitizes data, and inserts row into database. Example Usage <code> $data = array( 'Name'=>'Joan', 'Position'=>'2B' ); mysql_insert('players',$data); </code> returns: int|bool ID of inserted row if valid, false if invalid param: string $table Name of table to operate on param: array $data Associative array of data fields and values |
| mysql_update($table, $data, $query, $connector = "AND") X-Ref |
| Generates SQL query, sanitizes data, and updates row in database. Example Usage <code> //Updates Tom's row and moves him to Right Field $data = array( 'Position' => 'RF'); $query = array( 'Name' => 'Tom' ); mysql_update('players', $data, $query); ---- //Updates all players named 'Tom' or in Left Field and moves them to Right Field $data = array( 'Position' => 'RF'); $query = array( 'Name' => 'Tom', 'Position' => 'LF' ); mysql_update('players', $data, $query, "OR"); </code> param: string $table Name of table to operate on param: array $data Associative array of data fields and values param: array $query Associative array of query fields and values param: string $connector (Optional) connector for quiery ('AND' or 'OR') return: bool true or false on sucess or fail |
| mysql_remove($table, $query=array() X-Ref |
| Builds an SQL query, sanitizes the data, removes a row from the database. EXAMPLE USAGE <code> $query = array('ID'=>'3'); mysql_remove('players',$query); </code> param: string $table Name of table to operate on param: array $query Associative array of query field names and values param: string $connector (Optional) query connector ('AND' or 'OR') return: bool true or false for sucess or fail |
| mysql_select($table, $query=array() X-Ref |
| Builds an SQL query, sanatizes data, and return a MySQL resource object with the results. Typically used in conjunction with mysql_array or mysql_row_array to handle simple MySQL queries For example, to return an entire table: <code> mysql_select('Players'); </code> Or to return a select set of results: <code> $query = array('Name'=>'Tom'); mysql_select('Players',$query); </code> param: string $table Name of table to operate on param: array $query Associative array of query field names and values param: string $connector (Optional) query connector ('AND' or 'OR') return: object MySQL resource object with results |
| mysql_exists($table,$query=array() X-Ref |
| Runs a simple mysql SELECT query and returns true or false if results are found. Used to verify data (such as a username or password) when the existence of the fields (rather than their value) is what is sought param: string $table Name of table to operate on param: array $query Associative array of query field names and values param: string $connector (Optional) query connector ('AND' or 'OR') return: bool returns true if one or more results found, otherwise returns false |
| stripslashes_deep($value) X-Ref |
| Removes slashes from multi-dimensional arrays. Runs stripslashes() on all values in a multi-dimensial array. Used with mysql_array to remove slashes added by add_slashes() form mysql_insert(). Can also accept a standard array. param: array $value Array to be sanitized, may be single or multi-dimensional return: array Return array identical to one given but with slashes removed |
| Generated: Thu Jun 3 17:10:09 2010 | Cross-referenced by PHPXref 0.7 |