2013-06-21 113 views
-1

我正在尝试使用xampp php myAdmin连接mysql。mysql_connect():访问拒绝用户'root'@'localhost'(使用密码:否)

用户root默认情况下是在MySQL数据库中。

这里是我的代码:

<html> 
<body> 
<?php 
    [email protected]_connect("localhost", "root", ''); 
    if (!$dbCon) 
    { 
     echo('<p> '.mysql_error().'</p>'); 
     exit(); 
    } 
    else 
    { 
     if([email protected]_select_db("crs",$dbCon)) 
    { 
     die("<p>".mysql_error()."</p>"); 
    } 
    } 

    $qry="Create Table Courses(cCode VarChar(5) Not NULL Primary Key, cTitle VarChar(50) Not NULL, CH INT)"; 

    if(@mysql_query($qry)) 
    { 
     echo('<p>Courses Table has been created</p>'); 
    } 
    else 
    { 
     echo('<p>Courses Table can not be created due to' .mysql_error(). '</p>'); 

    } 
    $qry="Insert INTO Courses Values('C001','Intro to computing',4)"; 
     if (@mysql_query($qry)) 
     { 
      echo('<p>C001 is inserted </p>'); 
     } 
     else 
     { 
      echo('<p>Courses Table cannot be created due to'.mysql_error().'</p>'); 

     } 
     $qry="Insert INTO Courses Values ('C002', 'Programming Fundamentals',4), ('C003', 'Object Oriented Programming',4), ('C004', 'Operating Systems',4), ('C005', 'Data Structures and Algorithms',4)"; 
     if(@mysql_query($qry)) 
     { 
     echo('<p>4 Rows have been inserted</p>'); 
     } 
     else 

      echo('<p>Multiple Rows cant be inserted due to'.mysql_error().'</p>')   



?> 
</body> 
</html> 
+0

您的代码没有任何问题。然而,mysql已经建立了root用户需要密码从本地主机连接,你没有去你的电话mysql_connect。如果没有以管理员用户身份进行连接的方式,或者没有人记住他们如何设置mysql,则无法真正帮助您。 –

回答

2

您不使用密码和错误意味着root用户没有访问或不能访问,因为它需要一个密码。

+0

好吧,让我再试一次 – AngelChoco

+0

是的,你是正确的工作现在..谢谢:) – AngelChoco

相关问题