| Line 51... |
Line 51... |
| 51 |
// an array that contains the meta data from the query for each column
|
51 |
// an array that contains the meta data from the query for each column
|
| 52 |
'columnMetaData' => array(),
|
52 |
'columnMetaData' => array(),
|
| 53 |
// number of columns (fields) returned by query (select only)
|
53 |
// number of columns (fields) returned by query (select only)
|
| 54 |
'numfields' => 0,
|
54 |
'numfields' => 0,
|
| 55 |
// type of data returned, array of array, array of hash, or both
|
55 |
// type of data returned, array of array, array of hash, or both
|
| 56 |
'fetchType' => MYSQLI_ASSOC,
|
56 |
'fetchType' => MYSQLI_BOTH,
|
| 57 |
// human readable form of fetchType
|
57 |
// human readable form of fetchType
|
| 58 |
'returntype' => 'associative',
|
58 |
'returnType' => 'both',
|
| 59 |
// array of any errors which occurred
|
59 |
// array of any errors which occurred
|
| 60 |
'error' => array(),
|
60 |
'error' => array(),
|
| 61 |
// if set to a table name, all modifying queries are written to it
|
61 |
// if set to a table name, all modifying queries are written to it
|
| 62 |
// must contain, at a minimum, columns whenrun timestamp, whoran varchar and query text
|
62 |
// must contain, at a minimum, columns whenrun timestamp, whoran varchar and query text
|
| 63 |
// can be created with $this->buildAuditTable
|
63 |
// can be created with $this->buildAuditTable
|
| Line 181... |
Line 181... |
| 181 |
/*
|
181 |
/*
|
| 182 |
* doSQL
|
182 |
* doSQL
|
| 183 |
* Parameters: $query - string or array of strings to be executed
|
183 |
* Parameters: $query - string or array of strings to be executed
|
| 184 |
* $parameters - hash used to pass additional parameters, to include
|
184 |
* $parameters - hash used to pass additional parameters, to include
|
| 185 |
* $parameters['username'] = 'fred'; // username for logging
|
185 |
* $parameters['username'] = 'fred'; // username for logging
|
| 186 |
* $parameters['returntype'] = 'hash'; or array or both
|
186 |
* $parameters['returnType'] = 'hash'; or array or both
|
| 187 |
*
|
187 |
*
|
| 188 |
* executes one or more queries
|
188 |
* executes one or more queries
|
| 189 |
*
|
189 |
*
|
| 190 |
* If the query is one of select, show, describe or explain, it must
|
190 |
* If the query is one of select, show, describe or explain, it must
|
| 191 |
* be a single string. It will return the data results in a hash
|
191 |
* be a single string. It will return the data results in a hash
|
| Line 227... |
Line 227... |
| 227 |
$errors[] = array( 'id' => $this->errno, 'message' => $this->error );
|
227 |
$errors[] = array( 'id' => $this->errno, 'message' => $this->error );
|
| 228 |
} else {
|
228 |
} else {
|
| 229 |
$this->parameters['columnMetaData'] = $sth->fetch_fields(); // get metadata
|
229 |
$this->parameters['columnMetaData'] = $sth->fetch_fields(); // get metadata
|
| 230 |
$this->parameters['returnData'] = array(); // we'll put all the results in an array
|
230 |
$this->parameters['returnData'] = array(); // we'll put all the results in an array
|
| 231 |
// $fetchtype returns either an array of array, array of hash, or both. Default is array of hash
|
231 |
// $fetchtype returns either an array of array, array of hash, or both. Default is array of hash
|
| 232 |
if ( isset( $this->parameters['returntype'] ) ) {
|
232 |
if ( isset( $this->parameters['returnType'] ) ) {
|
| 233 |
$this->parameters[ 'fetchType' ] = $this->parameters['returntype'] == 'array' ? MYSQLI_NUM : (
|
233 |
$this->parameters[ 'fetchType' ] = $this->parameters['returnType'] == 'array' ? MYSQLI_NUM : (
|
| 234 |
( $this->parameters['returntype'] == 'both' ) ? MYSQLI_BOTH : MYSQLI_ASSOC
|
234 |
( $this->parameters['returnType'] == 'both' ) ? MYSQLI_BOTH : MYSQLI_ASSOC
|
| 235 |
);
|
235 |
);
|
| 236 |
} else { // default is associative array (hash)
|
236 |
} else { // default is both (hash and numeric)
|
| 237 |
$this->parameters[ 'fetchType' ] = MYSQLI_ASSOC;
|
237 |
$this->parameters[ 'fetchType' ] = MYSQLI_BOTH;
|
| 238 |
$this->parameters['returntype'] = 'associative';
|
238 |
$this->parameters['returnType'] = 'both';
|
| 239 |
}
|
239 |
}
|
| 240 |
// slurp all the stuff in
|
240 |
// slurp all the stuff in
|
| 241 |
while ( $values = $sth->fetch_array( $this->parameters[ 'fetchType' ] ) ) {
|
241 |
while ( $values = $sth->fetch_array( $this->parameters[ 'fetchType' ] ) ) {
|
| 242 |
$this->parameters[ 'returnData' ][] = $values;
|
242 |
$this->parameters[ 'returnData' ][] = $values;
|
| 243 |
}
|
243 |
}
|
| Line 314... |
Line 314... |
| 314 |
* Otherwise, function returns true
|
314 |
* Otherwise, function returns true
|
| 315 |
*/
|
315 |
*/
|
| 316 |
public function getOneRow( $sql = null ) {
|
316 |
public function getOneRow( $sql = null ) {
|
| 317 |
if ( isset( $sql ) )
|
317 |
if ( isset( $sql ) )
|
| 318 |
$this->parameters[ 'query' ] = $sql;
|
318 |
$this->parameters[ 'query' ] = $sql;
|
| 319 |
$save = $this->parameters[ 'returntype' ];
|
319 |
$save = $this->parameters[ 'returnType' ];
|
| - |
|
320 |
//print "<pre>" . print_r( $this->parameters['query'], true) . '</pre>';
|
| 320 |
$useAssociativeArray = true;
|
321 |
$useAssociativeArray = true;
|
| 321 |
$this->run();
|
322 |
$this->run();
|
| 322 |
$useAssociativeArray = $save;
|
323 |
$useAssociativeArray = $save;
|
| 323 |
if ( $this->parameters[ 'rowsAffected' ] == 1 ) {
|
324 |
if ( $this->parameters[ 'rowsAffected' ] == 1 ) {
|
| 324 |
$this->parameters[ 'returnData' ] = $this->parameters[ 'returnData' ][0];
|
325 |
$this->parameters[ 'returnData' ] = $this->parameters[ 'returnData' ][0];
|
| Line 333... |
Line 334... |
| 333 |
// or null no value returned
|
334 |
// or null no value returned
|
| 334 |
public function getOneDBValue( $sql = null ) {
|
335 |
public function getOneDBValue( $sql = null ) {
|
| 335 |
//print '<pre>' . $sql . '</pre>';
|
336 |
//print '<pre>' . $sql . '</pre>';
|
| 336 |
if ( isset( $sql ) )
|
337 |
if ( isset( $sql ) )
|
| 337 |
$this->parameters[ 'query' ] = $sql;
|
338 |
$this->parameters[ 'query' ] = $sql;
|
| 338 |
$save = $this->parameters['returntype'];
|
339 |
$save = $this->parameters['returnType'];
|
| 339 |
$this->parameters['returntype'] = 'array';
|
340 |
$this->parameters['returnType'] = 'array';
|
| 340 |
$this->run();
|
341 |
$this->run();
|
| 341 |
$this->parameters['returntype'] = $save;
|
342 |
$this->parameters['returnType'] = $save;
|
| 342 |
// print "<pre>" . print_r($this->parameters,true ) . "</pre>";
|
343 |
//print "<pre>" . print_r($this->parameters,true ) . "</pre>";
|
| 343 |
return $this->parameters[ 'rowsAffected' ] ? $this->parameters[ 'returnData' ][0][0] : null;
|
344 |
return $this->parameters[ 'rowsAffected' ] ? $this->parameters[ 'returnData' ][0][0] : null;
|
| 344 |
}
|
345 |
}
|
| 345 |
|
346 |
|
| 346 |
/*
|
347 |
/*
|
| 347 |
* function will attempt to make a constant ($value) safe for SQL depending on the type.
|
348 |
* function will attempt to make a constant ($value) safe for SQL depending on the type.
|