从php连接到mysql数据库,错误但未显示错误? [英] Connecting to a mysql database from php, error but no error shown?
问题描述
因此,我正在制作一个超级简单的站点,仅用于练习,您可以在其中键入内容,然后将其显示在页面上,但是它无法正常工作,我认为iv将其范围缩小到了它仅连接到数据库的起始位置
so I'm making a super simple site just for practice where you type something in an then its displayed on the page, but it wont work and i think iv narrowed it down to the begining where it connects to the database just
$server ="localhost";
$username ="root";
$password ="********";
$database ="user_accounts";
$connect=mysqli_connect($server,$username,$password,$database);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
我使用readline 6.2使用Apache/2.2.22(Debian),PHP 5.4.4-14和mysql Ver 14.14 Distrib 5.5.31运行服务器,用于debian-linux-gnu(armv7l)而且我注意到,即使我输入错误的密码也不会回显"错误行,所以我的问题是我是否像那样连接到localhost还是在其中做了其他错误?
Im running my server using Apache/2.2.22 (Debian), PHP 5.4.4-14 and mysql Ver 14.14 Distrib 5.5.31, for debian-linux-gnu (armv7l) using readline 6.2 and I've noticed that even when I type the password incorrectly it doesn't 'echo' the error line, so my question is do I connect to localhost like that or did i do something else wrong in there?
推荐答案
连接如下所示
<?php
$link = @mysqli_connect('localhost', 'root', '*******', 'user_accounts');
if (!$link) {
die('Connect Error: ' . mysqli_connect_errno());
}
?>
以下是根据您的请求在mysql脚本中创建用户
Below is create user in mysql script on your request
用户 newuser
,无需密码即可连接(不安全),不包含IDENTIFIED BY子句:
User newuser
to connect with no password (which is insecure), include no IDENTIFIED BY clause:
CREATE USER 'newuser'@'localhost';
要将密码分配给新创建的用户 newuser
,请使用IDENTIFIED BY和明文密码值:
To assign a password to new created user newuser
, use IDENTIFIED BY with the plaintext password value:
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'mypass';
要避免在知道明文密码的哈希值(PASSWORD()将为密码返回的值)的情况下指定该明文密码,请在关键字PASSWORD之前指定哈希值:
To avoid specifying the plaintext password if you know its hash value (the value that PASSWORD() would return for the password), specify the hash value preceded by the keyword PASSWORD:
CREATE USER 'newuser'@'localhost'
IDENTIFIED BY PASSWORD '*90E462C37378CED12064BB3388827D2BA3A9B689';
然后,您可以 GRANT
访问该 newuser
GRANT SELECT,INSERT,UPDATE,DELETE ON user_accounts.* TO'newuser'@'localhost';
您可以使用此链接生成哈希码.
You can use this link to generate the hash code.
这篇关于从php连接到mysql数据库,错误但未显示错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!