Forum Moderators: coopster
function checkIfAdmin($user,$pass)
{
$user = mysql_real_escape_string((get_magic_quotes_gpc())? stripslashes($user): $user);
$pass = mysql_real_escape_string((get_magic_quotes_gpc())? stripslashes($pass): $pass); $sql = "SELECT user FROM users WHERE user = '" . $user ."' AND pass = '" . $pass . "' AND user_level = '9' ";
$res = mysql_query($sql);
$num = mysql_num_rows($res);
if ($num > 0)
return true;
return false;
}
and change it to this for PEAR MDB2.php
function checkIfAdmin($user,$pass)
{
$user = mysql_real_escape_string((get_magic_quotes_gpc())? stripslashes($user): $user);
$pass = mysql_real_escape_string((get_magic_quotes_gpc())? stripslashes($pass): $pass); $sql = "SELECT user FROM users WHERE user = '" . $user ."' AND pass = '" . $pass . "' AND user_level = '9' ";
$res = $db->query($sql);
if ($res->numRows() > 0)
return true;
return false;
}
What do I do about the mysql_real_escape_string()?
Best Regards,
Brandon
You can also take the opportunity to write your own shortcut functions. For example, my db class has a function called insary() that takes a table name and associative array as parameters and takes care of constructing the insert statement, along with escaping strings & surrounding them with single quotes - it looks at the table structure to determine which array elements are numeric and which aren't.
The most efficient way to do it would be to write yourself a couple of database classes, one for each db you want to support and with identically named member functions. Then you only have to have one if statement:
if($dbmethod == 'mysql')
$db = new mysql_class();
elseif($dbmethod == 'postgresql')
$db = new postgresql_class();
elseif(. . .)
$db->query($sql);
If you did it as separate generically-named functions each one would have to test for the method.
If you look at the description for mysql_real_escape_string() [php.net] you can duplicate its functionality with regular expressions or str_replace() calls.