in reply to Multi-user-type interfaces made easy with Template Toolkit
$sql = "SELECT user_type FROM usersTable WHERE (username = $user_name) +; $sth = $dbh->prepare($sql) or die("Could not prepare!" . $dbh->errstr) +; $sth->execute() or die("Could not execute!" . $dbh->errstr);
Please don't. I guess this is not your exact code (it would not even compile due to missing doublequote), but still I think it's better to warn others. Either make sure the $user_name is properly escaped or even better use placeholders:
This is not only safer, but also most likely quicker. This way the database has a chance to cache the statement. The way you had it, the server had to recompile and recreate the execution plan whenever you needed to run the same query for a different user.$sql = "SELECT user_type FROM usersTable WHERE (username = ?)"; $sth = $dbh->prepare($sql) or die("Could not prepare!" . $dbh->errstr) +; $sth->execute($user_name) or die("Could not execute!" . $dbh->errstr);
HTH, Jenda
|
Support Denmark! Defend the free world! |
|
|---|