Jump to content

Query Function Help


JaredRitchey

Recommended Posts

I have a script that runs at the end of a batch process specifically built to clean out empty records.

 

How can I make it a function and then call the function.

 

Here is my query;

 

$sql="DELETE FROM ".$dbname." . property WHERE property . id=''";
mysql_query($sql) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());

$sql="DELETE FROM ".$dbname." . agents WHERE agents . ip_source=''";
mysql_query($sql) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());

$sql="DELETE FROM ".$dbname." . settings WHERE settings . prop_id=''";
mysql_query($sql) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());

 

I would like this to be in a function that i could specifically call the function. Why? Well because I have 5 different sets of queries like this set above and I'm going to build a conditional. So like if condition 1 then run use this function, condition 2, use function ??? etc and so on.

Link to comment
Share on other sites

specifically built to clean out empty records.

If you're validating your data correctly before it is inserted into the database then you shouldn't need to do this.

 

If you want to make your code a function then do this

function deleteEmptyRecords($dbname)
{
$sql="DELETE FROM ".$dbname." . property WHERE property . id=''";
mysql_query($sql) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());

$sql="DELETE FROM ".$dbname." . agents WHERE agents . ip_source=''";
mysql_query($sql) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());

$sql="DELETE FROM ".$dbname." . settings WHERE settings . prop_id=''";
mysql_query($sql) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());
}

 

Call it using

deleteEmptyRecords($dbname);

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.