Jump to content

mysql_real_escape_string and database selection/connection


Edward

Recommended Posts

 

Hi,

 

I'm trying to set up a connection to my database and insert some information while using mysql_real_escape_string. This is the demo I've seen:

 

$link = mysql_connect('localhost', 'root', 'root');
$sql = sprintf("INSERT INTO board ('id', 'name', 'password') VALUES ('%d', '%s', '%s', '%s') LIMIT 1",
			$id,
			$name,
			mysql_real_escape_string($description),
			mysql_real_escape_string($message));
if ($result = mysql_query($sql, $link)) {
echo 'ok';
}

 

However, I already have a function I want to use to connect, so once conntected, can I just do this?:

 

$sql = sprintf("INSERT INTO board ('id', 'name', 'password') VALUES ('%d', '%s', '%s', '%s') LIMIT 1",
			$id,
			$name,
			mysql_real_escape_string($description),
			mysql_real_escape_string($message));
if ($result = mysql_query($sql)) {
echo 'ok';
}

Archived

This topic is now archived and is closed to further replies.

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