我无法访问我的mysql数据库

时间:2014-09-12 03:01:02

标签: php mysql mysqli

你好我刚接触到php和Mysql即时通讯卡在这里任何人请帮助我。

错误讯息:

Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'suren'@'localhost' (using password: YES) in /home/nanot142/public_html/index.php on line 7
Database connection failed : Access denied for user 'suren'@'localhost' (using password: YES)(Access denied for user 'suren'@'localhost' (using password: YES))

我的代码

<?php

$dbhost ="localhost";
$dbuser ="suren";
$dbpass ="password";
$dbname ="nano";
$connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);

if(mysqli_connect_errno()) {
     die( "Database connection failed : " . mysqli_connect_error() . "(" . mysqli_connect_error() . ")" );}

?>

<?php

$query = "SELECT * FROM subjects";
$result = mysqli_query($connection, $query);

?>
<?php require_once("includes/functions.php"); ?>
<?php include("includes/layouts/header.php"); ?>

<div id="main"> 
   <div id="navigation">
      &nbsp;
   </div>
   <div id="page">
      <h2>Manage Content</h2>
   </div>
</div>

<?php include("includes/layouts/footer.php"); ?>
<?php mysqli_close($connection); ?>

1 个答案:

答案 0 :(得分:0)

试试吧..

$dbhost ="localhost";
$dbuser ="root";  //this is the username using to login localhost/phpmyadmin
$dbpass =""; //this is the password using to login localhost/phpmyadmin..if no                     //password leave it blank as given
$dbname ="test"; // this your database name

$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

else{
    echo "success";
}