在这个网站上发现了很多类似的问题,但这些问题的解决方案似乎没有回复。有问题的用户可以完全访问数据库,从我所知道的我不会错过任何逗号等。第二组眼睛会很棒。
提交的签名处于可接受的格式中以打开connectionError!:SQLSTATE [42000] [1044]拒绝用户'emkinsti_user1'@'localhost'访问数据库'签名'
<?php
// Tracks what fields have validation errors
$errors = array();
// Default to showing the form
$show_form = true;
// 1. Get the input from the form
// Using the PHP filters are the most secure way of doing it
$name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_STRING);
$output = filter_input(INPUT_POST, 'output', FILTER_UNSAFE_RAW);
// 2. Confirm the form was submitted before doing anything else
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// 3. Validate that a name was typed in
if (empty($name)) {
$errors['name'] = true;
}
// 3. Validate that the submitted signature is in an acceptable format
if (!json_decode($output)) {
$errors['output'] = true;
}
}
// No validation errors exist, so we can start the database stuff
if (empty($errors)) {
echo "Submitted signature is in an acceptable format";"<br/>";
$dsn = 'mysql:host=localhost;dbname=signatures';
$user = 'emkinsti_user1';
$pass = '6nqq103t26';
}
// 4. Open a connection to the database using PDO
try {
echo "Trying to open a connection";
$db = new PDO($dsn, $user, $pass);
}
catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
// Make sure we are talking to the database in UTF-8
$db->exec('SET NAMES utf8');
// Create some other pieces of information about the user
// to confirm the legitimacy of their signature
$sig_hash = sha1($output);
$created = time();
$ip = $_SERVER['REMOTE_ADDR'];
// 5. Use PDO prepare to insert all the information into the database
$sql = $db->prepare('INSERT INTO signatures (signator, signature, sig_hash, ip, created)
VALUES (:signator, :signature, :sig_hash, :ip, :created)');
$sql->bindValue(':signator', $name, PDO::PARAM_STR);
$sql->bindValue(':signature', $output, PDO::PARAM_STR);
$sql->bindValue(':sig_hash', $sig_hash, PDO::PARAM_STR);
$sql->bindValue(':ip', $ip, PDO::PARAM_STR);
$sql->bindValue(':created', $created, PDO::PARAM_INT);
$sql->execute();
// 6. Trigger the display of the signature regeneration
$show_form = false;
// mysql_close($db);
$db = null;
?>
答案 0 :(得分:1)
emkinsti_user1'@'localhost'到数据库'签名' 如果您使用的是CPanel,则CPanel也会对数据库名称使用前缀:
您使用:emkinsti_user1作为用户。
您应该使用:emkinsti_signatures作为数据库名称。
登录您的CPanel,您将在那里找到带有前缀
的数据库名称答案 1 :(得分:0)
尝试http://php.net/manual/en/pdo.getavailabledrivers.php查看PDO是否支持数据库。
<?php
print_r(PDO::getAvailableDrivers());
?>
只是一个想法。当它不是时,我会期待另一条错误消息。因此,据我所知,当从本地主机访问数据库时,用户无权访问。