【问题标题】:connecting to mysql using xampp [duplicate]使用xampp连接到mysql [重复]
【发布时间】:2017-01-27 13:23:53
【问题描述】:

我是使用 xampp 的新手,直到一周前我使用托管服务器进行 php 开发。我遇到了可能是新手的问题,如果提供任何建议,我将不胜感激。

我已经让 phpmyadmin 工作并创建了一个数据库和一个具有完全权限的用户。我会在托管服务器上做的所有事情。当我尝试使用 mysqli 连接时,出现以下错误:

警告:mysqli::mysqli(): (HY000/1045): Access denied for user 'cromwell'@'localhost' (using password: YES) in C:\xampp\htdocs\cromwell\dbconnect.php on line 2 连接失败:用户 'cromwell'@'localhost' 的访问被拒绝(使用密码:YES)

使用以下 SQL 设置用户帐户权限:

REVOKE ALL PRIVILEGES ON *.* FROM 'cromwell'@'localhost'; 
GRANT ALL PRIVILEGES ON *.* TO 'cromwell'@'localhost' REQUIRE NONE WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;

连接脚本如下:

<?
$mysqli = new mysqli("localhost", "cromwell", 'password', "cromwell");

if ($mysqli->connect_errno) {
    printf("Connect failed: %s\n", $mysqli->connect_error);
    exit();
}

?>

根据我创建用户时 phpmyadmin 的设置,用户和数据库都被命名为 cromwell。

我假设我在用户设置或如何从脚本中寻址数据库中遗漏了一些简单的东西。

感谢您的任何帮助或建议。

【问题讨论】:

  • 您在重新创建帐户时没有添加密码,但您在 PHP 脚本连接中使用了密码
  • 谢谢!我会在 phpmyadmin 中为用户设置密码,但不会为用户与数据库的连接设置密码。就像我说的,新手错误。

标签: php mysql mysqli xampp


【解决方案1】:
Sql connection using PDO Methode:

<?php
/* Database config */
$db_host        = 'localhost';
$db_user        = 'root';
$db_pass        = '';
$db_database    = 'sales'; 

/* End config */

$db = new PDO('mysql:host='.$db_host.';dbname='.$db_database, $db_user, $db_pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

?>

【讨论】:

    【解决方案2】:
                        Sql connection using MySql Methode:
    
                        ?php
                        $database="gzone";
                        $username="root";
                        $password="";
                        $conn = mysql_connect("","$username","$password");
                        if(!$conn)
                        {
                        die('<h2>connection can not be established properly :</h2>'. mysql_error());
                        }
                        $db=mysql_select_db($database);
                        if(!$db)
                        {
                        die('<h2>fatal error in database</h2>'.mysql_error());
                        }
                        ?>
                    ///////////////////////////////////////////////////////////////////
                    LOgin in PhP:
    
                        <?php 
                        session_start();
                        include('conn.php');
                        $email = $_POST['email'];
                        $password = $_POST['password'];
                        $sql = mysql_query("SELECT user_type,email FROM guser WHERE email= '$email' and password='$password'") or die(mysql_error());
                        if(mysql_num_rows($sql) ==1){
                            $result = mysql_fetch_assoc($sql);
                            $user_type= $result['user_type'];
    
                            session_start();  
                            if($user_type!='admin'){
    
                                $_SESSION['uname'] = $email;
                                $_SESSION['user_type']= $user_type;
                                header("location:index.php");
                                exit();
    
                            }
                            else{
    
                                $_SESSION['uname'] = $email;
                                $_SESSION['user_type'] = $user_type;
                                header("location: ./admin_data/admin.php");
                                exit();
    
                            }
                            }else{
                            header("location:index.php?message=invalid-user");
                                    exit(); 
                        }
    
    
    
                        ?>
    
    
                ////////////////////////////////////////////////////
                SignUp in Php:
    
                <?php
                include_once('conn.php');
                $name=$_POST['name'];
                $password=$_POST['password'];
                $email=$_POST['email'];
                $cnic=$_POST['cnic'];
                $phoneno=$_POST['phon_no'];
                $visacard=$_POST['visa'];
                $DOB=$_POST['dob'];
    
                $q="insert into guser(username,password,email,cnic_no,phone_no,visa_card,dob,user_type)values('".$name."','".$password."','".$email."','".$cnic."','".$phoneno."','".$visacard."','".$DOB."','user')";
                if(!mysql_query($q,$conn))
                {
                die('fatal error'.mysql_error());
                }
                header('location: GAMMING ZONE.COM.php?signup=t');
                exit();
    
                ?>
            //////////////////////////////////////////////////
            Java Script Validation is:
    
            <script>
    
            function validlogin(){
    
    
                var email1_value = document.getElementById("email1").value;
                var p1_value = document.getElementById("password").value;
                 if(!email1_value)
                    {                                                             
                        alert("Invalid email!");               
                        return false;
                    }
                    if(p1_value.length==0)
                    {
                        alert("please enter password!");
                        return false;
                    }
    
    
                }
    
             function validation(){
    
                 var name_value = document.getElementById("name").value;
                   var p_value = document.getElementById("password2").value;
                   var cp_value = document.getElementById("retpassword").value;
                    var email_value = document.getElementById("email").value;
                    var cnic_value = document.getElementById("nic").value;
                    var phone_value = document.getElementById("phone").value;
                    var visa_value = document.getElementById("visa").value;
                    var DOB_value = document.getElementById("dob").value;
    
                    var reg_nic = /^[1-9]{1}[0-9]{4}\-[0-9]{7}\-[0-9]{1}$/;
                    var reg_ph = /^03[0-9]{2}\-[0-9]{7}$/;
                    var reg_visa=/^[1-9]{1}[0-9]{15}$/;
    
    
                    if(name_value.length==0){
    
                        alert("Name lenght is not okay!");
                        return false;
                    }
                    //alert(p_value);
                    if(p_value.length==0)
                    {
                        alert("please enter password!");
                        return false;
                    }
                        if(!cp_value)
                    {
                        alert("must retype password!");
                        return false;
                        }
    
                    if(p_value!=cp_value){
    
                        alert("Password dose not match!");
                        return false;
                    }
                   if(!email_value)
                    {                                                             
                        alert("Invalid email!");               
                        return false;
                    }
                    if(reg_nic.test(cnic_value)==false){
                        alert("Invalid Nic!");
                        return false;
                    }
                    if(reg_ph.test(phone_value)==false){
                         alert("Invalid Mobile no!");
                        return false;
                    }
                     if(reg_visa.test(visa_value)==false){                                                             
                        alert("Invalid visa card number!");               
                        return false;
    
                    }
                     if(!DOB_value){                                                             
                        alert("Invalid date of birth!");              
                        return false;
                    }
                }
    
    
    
    
                function search(){
    
    
                var search = document.getElementById("sname").value;
    
                 if(search.length==0)
                    {                                                             
                        alert("Search for games...!");               
                        return false;
                    }
                    }
            </script>
    
        /////////////////////////////////////////////////////////
        Query string Back to action page through Get Function:
    
         <?php
             session_start();
             if(isset($_SESSION['uname']) && isset($_SESSION['user_type']) && $_SESSION['user_type']=='user')
             {
                 echo'<h3 style="color:white">wellcome '.$_SESSION['uname'].' </h3>';
                 }
                 if(isset($_GET['signup'])){
            echo '<h3 style="color:white">you are successfully signup.</h3>';
    
        }
    
            ?>
    
     <div class="main-body-section-left-title"><h2>MANAGE USER'S</h2></div>
        <?php
        include_once('../conn.php');
    
    
        $q=mysql_query("select * from guser");
    ?>
    <form action="manage_user.php" method="post" style="margin-left:-150px;">
    <table class="table_decoration" border="7px" >
        <tr  class="row_decoration">
            <th style="color:#00ff00;">USER NAME</th>
            <th style="color:#00ff00;">EMAIL</th>
            <th style="color:#00ff00;">PASSWORD</th>
            <th style="color:#00ff00;">CNIC_NO</th>
            <th style="color:#00ff00;">PHONE_NO</th>
            <th style="color:#00ff00;">VISA CARD NO</th>
            <th style="color:#00ff00;">DOB</th>
            <th style="color:#00ff00;">USER TYPE</th>
            <th style="color:#00ff00;">DELETE</th>
            <th style="color:#00ff00;">UPDATE</th>
            <th><a href="add_user.php"><p style="color:#00ff00;">ADD</p></a></th>
        </tr>
        <?php
    
        while($row=mysql_fetch_array($q)){
        echo ' <tr class="row_dec">
                    <td style="color:white">'.$row['username'].'</td>
                    <td style="color:white">'.$row['email'].'</td>
                    <td style="color:white">'.$row['password'].'</td>
                    <td style="color:white">'.$row['cnic_no'].'</td>
                    <td style="color:white">'.$row['phone_no'].'</td>
                    <td style="color:white">'.$row['visa_card'].'</td>
                    <td style="color:white">'.$row['dob'].'</td>
                    <td style="color:white">'.$row['user_type'].'</td>
                    <td>
                     <a href="#?email='.$row['email'].'" onClick="if(window.confirm(\'Are you want to delete this user? \'))
                    { window.location =\'delete_user.php?email='.$row['email'].'\'; }">
                    <p style="color:yellow;">Delete</p></a>
                    </td>
                    <td> <a href="update_user.php?email='.$row['email'].'"><p style="color:yellow">Update </p></a></td>
                </tr>';
    
        }
    
        ?>
    </table>
    
          </form> 
    
             </div>
    

    【讨论】:

      猜你喜欢
      • 2012-09-18
      • 2018-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-19
      • 1970-01-01
      • 2011-05-30
      相关资源
      最近更新 更多