本文整理匯總了PHP中PDO::setATTRIBUTE方法的典型用法代碼示例。如果您正苦於以下問題:PHP PDO::setATTRIBUTE方法的具體用法?PHP PDO::setATTRIBUTE怎麽用?PHP PDO::setATTRIBUTE使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PDO
的用法示例。
在下文中一共展示了PDO::setATTRIBUTE方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: PDO
<html>
<head>
<title>Table</title>
</head>
<body>
<form action="" method="POST">
Table name <input type="text" name="dbname" required><br>
Login <input type="text" name="login" required><br>
Password <input type="password" name="pass" required><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
<?php
if ($_POST['dbname'] == 'users1') {
$conn = new PDO('mysql:host=127.0.0.1:3306; dbname=db1', 'root', NULL);
$conn->setATTRIBUTE(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->exec("CREATE TABLE IF NOT EXISTS Users1 (uid int AUTO_INCREMENT,\r\n\t name varchar(255),\r\n\t password varchar(255),\r\n PRIMARY KEY (uid))");
print "Table already created" . "<br>";
$admin = $conn->prepare("SELECT * FROM Users1 WHERE name = '{$_POST['login']}' AND password = '{$_POST['pass']}'");
$admin->execute(array('name' => $_POST['login'], 'password' => $_POST['pass']));
$adminok = $admin->fetchALL();
if (count($adminok)) {
print "Welcome admin!";
} else {
print "Access denied. Unknown login or password";
}
}
if (isset($_POST['dbname']) && $_POST['dbname'] !== 'users1') {
print "Unknown table name";
}