Mathias

Common SQL functions

4 posts in this topic

Note, all of my functions belong to classes, but I am posting only snippets of my functions to avoid boredom and giving away all my secrets. Please post corrections, suggestions, and your own related functions.


Understand this lad, fate is a fickle lady. Work with the hand you're dealt and you may just be able to run your flag up the pole. Don't, and well, you may just find your mast cut down.

Share this post


Link to post
Share on other sites


        //-------------------------------------------------------------------------
// Function: mysqlSelect
// Author: Andrew Hinkle
// Modified: 06/20/2007
// Description: Return the select query results in an array.
//-------------------------------------------------------------------------
public function mysqlSelect($sSQL)
{
// Was the database connected?
if (empty($this->_pConnect)) return 0;

// Run the query and capture the results.
$mResult = mysql_query($sSQL);

// Return an empty array if no results were returned.
if (empty($mResult)) return array();

// Convert the mysql result to a standard array.
$aResult = array();
while ($aFetched = @mysql_fetch_array($mResult, MYSQL_ASSOC))
{
// Append the fetched array to the result array.
$aResult[] = $aFetched;
}

// mysql memory clean up.
@mysql_free_result($mResult);

return $aResult;
}
[/CODE]


Understand this lad, fate is a fickle lady. Work with the hand you're dealt and you may just be able to run your flag up the pole. Don't, and well, you may just find your mast cut down.

Share this post


Link to post
Share on other sites
        //-------------------------------------------------------------------------
// Function: mysqlQuery
// Author: Andrew Hinkle
// Modified: 06/20/2007
// Description: Run the query on the table, but do not return any results.
//-------------------------------------------------------------------------
public function mysqlQuery($sSQL)
{
// Was the database connected?
if (empty($this->_pConnect)) return (0);

// Run the query and capture the results.
$mResult = mysql_query($sSQL);

// Results were not returned.
if (empty($mResult)) return 0;

// mysql memory clean up.
@mysql_free_result($mResult);

// Results were returned and freed.
return 1;
}
[/CODE]


Understand this lad, fate is a fickle lady. Work with the hand you're dealt and you may just be able to run your flag up the pole. Don't, and well, you may just find your mast cut down.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now