Jump to content

mysql_compare


Garethp

Recommended Posts

I just built a class, thought this might be the place to share it. It compares a class to a mysql value. Here it is

 

mysql_compare($Table, $IDColumn, $ID, $CompareCol, $Value);

 

function mysql_compare($Table, $Columna, $ID, $Columnb, $Value)
{

$Error = 0;

$Query = mysql_query("SELECT * FROM `$Table` WHERE `$Columna`='$ID'");

if(mysql_num_rows($Query) > 1)
	{
	$Error = 1;
	$Errortext = "Identifier is not unique";
	}
else if(mysql_num_rows($Query) == 0)
	{
	$Error = 1;
	$Errortext = "Row does not exist";
	}
else
	{
	$Show = mysql_fetch_array($Query);
	$Compare = $Show["$Columnb"];

	if($Compare == $Value)
		{
		$Errortext = 1;
		}
	else
		{
		$Errortext = 0;
		}
	}

return ($Errortext);
}

Link to comment
Share on other sites

 

Description

string mysql_escape_string ( string $unescaped_string )

 

This function will escape the unescaped_string , so that it is safe to place it in a mysql_query(). This function is deprecated.

 

This function is identical to mysql_real_escape_string() except that mysql_real_escape_string() takes a connection handler and escapes the string according to the current character set. mysql_escape_string() does not take a connection argument and does not respect the current charset setting.

 

 

(Underlining by me)

Link to comment
Share on other sites

What exactly does the last paragraph mean? I get that my version is depreciated.

 

Quick question, how do I update the PHP version on EasyPHP? Because if I can't, I need to find another way to host my own PHP server, and last time I tried I had no luck

Link to comment
Share on other sites

It means, that mysql_real_escape_string() can only be run after mysql_connect(). It needs a mysql connection to be present, so that it could escape the string according to the charset defined by for example

 

mysql_query(""SET NAMES 'utf8'");

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.