与数据库连接 [英] Connecting with database
问题描述
dbconnect.php:
<?php
if(!mysql_connect(localhost,doesnews_users,))
{
die('oops connection problem! - >'.mysql_error());
if(!mysql_select_db(doesnews_editor))
{
die('oops database selection problem! - >'.mysql_error());
}
?>
这就是我得到的回应:
< blockquote>
警告:在
/ home / doesnews / public_html / dbconnect中,mysql_connect():拒绝用户
'doesnews_users'@'localhost'(使用密码:NO)第2行的oops连接
问题! - >访问被拒绝用户'didnews_users'@'localhost'
(使用密码:NO)
这是我的 register.php:
<?php
session_start();
if(isset($ _ SESSION ['user'])!=)
{
header(Location:home.php);
}
include_once'dbconnect.php';
if(isset($ _ POST ['btn-signup']))
{
$ uname = mysql_real_escape_string($ _ POST ['uname']);
$ email = mysql_real_escape_string($ _ POST ['email']);
$ upass = md5(mysql_real_escape_string($ _ POST ['pass']));
if(mysql_query(INSERT INTO users(username,email,password)VALUES('$ uname','$ email','$ upass')))
{
?> ;
< script> alert('successfully registered');< / script>
<?php
}
else
{
?>
< script> alert('注册您时发生错误...');< / script>
<?php
}
}
?>
在你的cPanel中,你应该可以看到db设置
主机,用户名
如果您忘记密码,您还可以编辑您的数据库设置
另一种选择是检查你的邮件,大多数时候创建一个新的数据库时,托管公司向你发送有关如何连接到你的数据库的信息。
检查帮助从托管公司,他们通常还提供有关如何连接的详细信息。
I am stuck and don't know what to do. I have issue connecting with my MySQL. I am using the information provided for me through Cpanel because I know that root password is only for the server admin and i am using shared hosting and can not get that . I have also give all privileges to the user even though I know I will change this once I got hold of this issue. my codes for connecting database are dbconnect.php:
<?php
if(!mysql_connect("localhost","doesnews_users",""))
{
die('oops connection problem ! --> '.mysql_error());
}
if(!mysql_select_db("doesnews_editor"))
{
die('oops database selection problem ! --> '.mysql_error());
}
?>
this is what i got in response:
Warning: mysql_connect(): Access denied for user 'doesnews_users'@'localhost' (using password: NO) in /home/doesnews/public_html/dbconnect.php on line 2 oops connection problem ! --> Access denied for user 'doesnews_users'@'localhost' (using password: NO)
and this is my register.php:
<?php
session_start();
if (isset($_SESSION['user']) != "")
{
header("Location: home.php");
}
include_once 'dbconnect.php';
if (isset($_POST['btn-signup']))
{
$uname = mysql_real_escape_string($_POST['uname']);
$email = mysql_real_escape_string($_POST['email']);
$upass = md5(mysql_real_escape_string($_POST['pass']));
if (mysql_query("INSERT INTO users(username,email,password) VALUES('$uname','$email','$upass')"))
{
?>
<script>alert('successfully registered ');</script>
<?php
}
else
{
?>
<script>alert('error while registering you...');</script>
<?php
}
}
?>
in your cpanel you should be able to see the db settings host,username
you could also edit your db settings in case you forgot your password
another option is to check your mail, most of the time when creating a new database the hosting company sends you information on how to connect to your db.
Check the help from the hosting company, they usually also provide details on how to connect.
这篇关于与数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!