【问题标题】:MySQL and PHP works locally, not on GoDaddyMySQL 和 PHP 在本地工作,而不是在 GoDaddy
【发布时间】:2010-01-08 05:17:46
【问题描述】:

我正在使用共享 Linux 托管,而我编写的一些 PHP 无法与服务器上的数据库一起使用。

编辑:

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

编辑:

不工作是指我无法读取数据库。我已经搞砸了,知道数据库正在运行,并且当我修改密码变量时,我得到“拒绝访问”。此外,在 localhost 上,密码不同并且有效。

编辑 2: 我现在正在使用示例脚本。它现在显示一个空白页。至少没有错误...我将密码更改为字母数字。我没有使用“本地主机”。

编辑 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

【问题讨论】:

  • 您是否尝试过 echo'n phpinfo(); 以确保它开始工作?我记得如果你选择 Linux 主机,你会得到 PHP,所以它应该在那里。
  • php 中的所有其他内容都可以在服务器上运行。 PHP 工作。
  • “它不起作用”是什么意思?您是否收到任何类型的错误(如有必要,您应该尝试启用 error_reporting)?
  • 我不是GoDaddy用户,但一般来说,您的帐户界面应该有一些关于管理数据库的部分,允许您创建数据库,设置密码。仔细检查以确保您拥有正确的密码。您还可以检查数据库是否与您的网络主机一起存在。

标签: php mysql


【解决方案1】:

你在mysql连接中使用了“localhost”吗?

大多数托管服务主机 mysql 在不同的机器上,通常 localhost 不起作用,需要输入服务器提供的确切 url。

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

【讨论】:

    【解决方案2】:

    对于 GoDaddy,您必须使用 localhost 作为数据库服务器。在托管管理器中的数据库 -> MySQL 下有示例 PHP 代码可以提供帮助。

    【讨论】:

    • 使用本地主机作为服务器。
    【解决方案3】:

    您以前访问过数据库吗?你有安装 phpMyAdmin 吗?哈希不应该是问题。如果它允许您将其设置为密码,那么您肯定可以登录。您能否发布您正在使用的代码,以便我们检查是否退出?

    【讨论】:

    • 我之前访问过 GoDaddy 上的其他数据库,不是这个。我认为中间有一个 # 的事实会使事情变得混乱,因为它是 PHP 的注释字符。 (除了 /**/ 和 //)也许 GoDaddy/PHPMyAdmin 有一些解析它的方法。
    • 散列是注释,只要它在字符串之外。与此无关。
    【解决方案4】:

    我用过一两次GoDaddy(顺便说一句,服务很糟糕),只要我记得,mysql主机,即98%localhost,应该设置为另一个主机,但我不确定.也许你应该从那里开始检查。

    【讨论】:

      【解决方案5】:

      自我说明:

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

      【讨论】:

        猜你喜欢
        • 2014-04-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-06-03
        • 1970-01-01
        • 1970-01-01
        • 2018-03-10
        相关资源
        最近更新 更多