代码之家  ›  专栏  ›  技术社区  ›  Moshe

mysql和php在本地工作,而不是在godaddy上

  •  2
  • Moshe  · 技术社区  · 15 年前

    我使用的是共享的Linux主机,我写的一些PHP在服务器上无法与我的数据库配合使用。

    编辑:

    我解决了这个问题。我不小心从配置文件中删除了“数据库”连接变量。真的。我真傻。

    编辑:

    不工作的意思是我看不懂数据库。我已经搞砸了,知道数据库正在运行,当我修改密码变量时,我得到了“拒绝访问”。此外,在本地主机上,密码是不同的,并且可以工作。

    编辑2: 我现在正在使用一个示例脚本。现在它显示一个空白页。至少没有错误…我把密码改成字母数字。我没有使用“localhost”。

    编辑3:使用正确的密码和服务器信息,我使用mysql_error()得到以下错误。我没有在数据库URL中使用前导http://。

    无法通过socket'/var/lib/mysql/mysql.sock'连接到本地mysql服务器(2)

    编辑4:

    这是我的连接码,请注意 nl() report() 是分别回送换行和诊断消息的预定义函数。连接变量位于上面包含的外部文件中。我查过了-包括服务都很好。

    //////////////////////////////
    // Connect to the database  /////////////////////////////////////////
    //////////////////////////////
    
    //report -  Attemting to establish connection ...
    report(4);
    
    ////
    //Step 1) Set connection in variable
    ////
    
    $conn = mysql_connect($server, $user, $pass);
    
    ////
    // Step 2) Verify the connection
    ////
    
    if(!$conn){
        //report - failed, see next line...
        report(5);
        //report - FATAL ERROR: Check database name, username and password.
        report(9);      
    }else{
      //report - done!
      report(7);
    }
    
    //report - Selecting database ...
    report(6);
    
    ////
    // Step 3) Select the database
    ////
    
    $db_select = mysql_select_db($database);
    
    ////
    // Step 4) Verify successful selection
    ////
    
    if(!$db_select){
        //report - failed, see next line...
        report(5);
        //report - FATAL ERROR: Could not select database.
        report(8);  
    }else{
      //report - done!
      report(7);
    }
    
    //report -  Running query ...
    report(10);
    
    ////
    // Step 5) Create the original the query
    ////
    
    $selector = " * ";
    $target = "`properties`";
    $condition = "1";
    
    $sql = "SELECT " . $selector . " FROM " . $target . " WHERE " . $condition;
    
    ////
    //  Step 6) Check for a $_GET[] parameter
    ////
    
    if($_GET['listing'] && !is_null($_GET['listing'])){                 //if a listing number was supplied
        $listingNum = htmlentities($_GET['listing']);                   //safety first - clean it from code injections                      
        $pattern = '/\b[0-9]{1,6}\b/';                                  //define a range of valid, sercheable listings
        if(preg_match($pattern,$listingNum) == 1){                      //if the listing id is a valid one
            $sql .= " AND `listing_id` =" .$listingNum . "";            //search for it in the database
        }elseif($exp == 0){                                             //if the listing number is out of range         
            if($listingNum != "all"){                                   //check if the "all" keyword was ommitted - if it was not supplied.
                //report - failure ... see below
                report(5);
                //report - Invalid listing ID
                report(12);
                //
                // Invalid Listing ID...
                //
            }       
        }
    }else if(!$_GET['listing']){
        //report - failure ... see below
        report(5);
        //report - Invalid listing ID
        report(12);
        //
        //No listing ID
        //
    }
    
    
    if(!$sql){
        //report - failed, see next line...
        report(5);
        //report - FATAL ERROR: Could not run query.
        report(11);
        //
        // For some reason the query doesn't exist here. I really do wonder why.
        //
    }else{
      //report - done!
      report(7);
      nl();
    }
    
    $result = mysql_query($sql);    //perform the actual query
    
    if(!$result){
        echo("There's been some sort of error with the search lookup. Here are the details: \n" . mysql_error());
    }
    
    mysql_close($conn);         //close the connection to the SQL server
    
    5 回复  |  直到 8 年前
        1
  •  3
  •   YOU    15 年前

    你用过“ 本地服务器 “在MySQL连接中?

    大多数托管服务主机mysql位于不同的机器上,通常本地主机不工作,需要放置服务器提供的确切URL。

    密码中的字符“”应该没有问题,但您的密码应该在引号内,如“123 123”,我不确定123 123是否有效。

        2
  •  2
  •   Grant Paul    15 年前

    对于戈达迪,你必须 使用 localhost 作为数据库服务器。在宿主管理器中的databases->mysql下有一些PHP示例代码可以帮助您。

        3
  •  0
  •   B Squared    15 年前

    你以前访问过数据库吗?是否安装了phpmyadmin?散列不应该是问题所在。如果它允许您将其设置为密码,那么您可以确定地登录。你能把你正在使用的代码贴出来吗?这样我们就可以查出来了。

        4
  •  0
  •   metrobalderas    15 年前

    我用过一两次godaddy(糟糕的服务btw),只要我记得,mysql主机,98% localhost ,应该设置为另一个主机,但我不确定。也许你应该去那里看看。

        5
  •  0
  •   Moshe    15 年前

    自我说明:

    下次发生这种情况时,请确认您在MySQL中选择的数据库