-1

我决定在这里推荐后使用 PDO,我在下面找到了这段代码。这些代码足以防止 SQL 注入?上课是更好的选择吗?

<?
class database {

private $hostname;
private $database;
private $username;
private $password;
private $pdo;
function __construct($hostname, $database, $username, $password) {

$this->pdo = new PDO("mysql:host={$this->hostname};port={$this->port};dbname={$this->database}", $this->username, $this->password, array(PDO::ATTR_PERSISTENT => true));

} catch(PDOException $e) {

print "<b>Error - Connection Failed: </b>" . $e->getMessage() . "<br/>";
die();
}
}

public function query($query, $bind = null) {
global $pdo;

$this->statement = $this->pdo->prepare($query);
$this->statement->execute($bind);
}



$date = date("Y-m-d H:i:s", time());

$database->query('INSERT INTO users_inactive(verCode, username, password, email, date) VALUES (?, ?, ?, ?, ?)', array($verCode, $username, $password, $email, $date));

$success[] = "You account has been created!";

?>
4

1 回答 1

1

此代码包含语法错误、速记和全局变量。不,它不够好用。

于 2012-07-27T16:39:42.550 回答