PHP脚本不能连接到数据库? [英] PHP script wont connect to database?

查看:199
本文介绍了PHP脚本不能连接到数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的网站加载某些网页时,我有一个脚本,将在点行中向用户表添加点。这是我的脚本

When certain pages load on my site I have a script that will add points to the users table in the points row. Here is my script

<?php

session_start();
$db = mysqli_connect("hostname", "username", "password", "database");

$username = $_SESSION['username']; 

mysqli_query($db, 'UPDATE login_users SET points_column=points_column+1 WHERE username=$username');


?>

我已经检查了主机名,用户名和密码的详细信息,一切正常,错误

I have already checked the host name, username and password details and everything is correct but I keep getting this error


警告:mysqli_connect()[function.mysqli-connect]:(28000/1045):拒绝用户'a5950626_jlf'@ '10 .1.1.34'(使用密码:YES)在/home/a5950626/public_html/application/home.php第5行

Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'a5950626_jlf'@'10.1.1.34' (using password: YES) in /home/a5950626/public_html/application/home.php on line 5

PHP错误消息

警告:mysqli_query()期望参数1为mysqli,boolean
在第9行的/home/a5950626/public_html/application/home.php中提供

Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /home/a5950626/public_html/application/home.php on line 9

任何想法什么问题可能是或如何解决它?感谢!

Any ideas what the problem could be or how to fix it? Thanks!

推荐答案

很好,错误消息清楚地说,访问被拒绝,所以hostname / username / password /

Well, the error message clearly says that access is denied, so either hostname/username/password/database is wrong or the user doesn't have the required permissions.

如何设置权限,在本例中为all:

How to set up permissions, in this example all:

GRANT ALL PRIVILEGES ON database_name TO user@host IDENTIFIED BY 'password';
FLUSH PRIVILEGES;

Host是您要连接的地方。 可以用作wildchar。请参阅文档中的更多详细示例。 (您可以在错误消息btw中看到您的用户+主机)

Host is where you'd be connecting from. % can be used as a wildchar. See more detailed examples at the documentation. (you can see your user + host in the error message, btw)

另外,您应该在尝试使用数据库链接之前检查连接是否成功一个查询。

As a side note, you should check that connection was successful before trying to use the database link in a query.

这篇关于PHP脚本不能连接到数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆