首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >解决PHP错误: SQLSTATE[42000] [1044]

解决PHP错误: SQLSTATE[42000] [1044]
EN

Stack Overflow用户
提问于 2015-03-04 15:42:10
回答 2查看 1.6K关注 0票数 0

在这个网站上发现了很多类似的问题,但是这些问题的解决方案似乎没有得到回应。有问题的用户可以完全访问数据库,据我所知,我没有丢失任何逗号等等。第二组眼睛就太好了。

提交的签名在可接受的formatTrying中打开connectionError!:SQLSTATE42000访问,拒绝用户‘emkinsti_ user 1’@‘localhost’到数据库‘签名’

代码语言:javascript
复制
<?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;
?>
EN

回答 2

Stack Overflow用户

发布于 2016-08-19 20:54:54

emkinsti_ uses 1‘@’localhost‘到数据库’签名‘如果您使用的是CPanel,CPanel也会在数据库名称中使用前缀:

您使用: emkinsti_user1作为用户。

您应该使用: emkinsti_signatures作为数据库名。

登录到您的CPanel中,您将在那里找到带有前缀的数据库名

票数 1
EN

Stack Overflow用户

发布于 2015-03-04 15:51:24

试试http://php.net/manual/en/pdo.getavailabledrivers.php,看看PDO是否支持数据库。

代码语言:javascript
复制
<?php
print_r(PDO::getAvailableDrivers());
?>

只是个主意。因此,据我所知,用户在从本地主机访问数据库时没有访问权限。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28858605

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档