Jump to content
Mathias

Common SQL functions

Recommended Posts

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...