【问题标题】:PHP Strange error "0:". Possible Object syntax problem?PHP 奇怪的错误“0:”。可能的对象语法问题?
【发布时间】:2025-11-25 20:15:01
【问题描述】:

我正在尝试将网站从一家托管公司转移到另一家托管公司。在客户端拥有托管和域之前,我一直在使用 000webhost。现在客户有了自己的域和主机,使用 FatCow.com,我不能为我的生活调试我的 PHP 代码。我没有收到任何错误。我有一个成功的数据库连接。如果您按程序显示数据,它可以工作,但是当我尝试使用我的原始对象时,有些东西会破坏并且只返回“0:”。我有所有错误。

在网站运行的旧服务器上:

PHP 版本 5.2.11

MySQL 版本:5.0.81

在我得到“0:”的新服务器上:

PHP 版本 5.2.12

MySQL 版本 5.0.32

我已经设置了一个测试页面来测试使用数据库连接的变量的输出。

下面是我的代码:

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
try
  {
   $link = mysql_connect('connectionstring', 'username', 'password'); 
  if (!$link) { 
      die('Could not connect: ' . mysql_error()); 
  } 
  else{
  $db = mysql_select_db('a8210422_lit'); 
  }
  if($db){



     include_once('admin/classes/clsPOW.php');
     include_once('admin/classes/clsProviders.php');

     $pow = new POW();
     $prov = new Providers();

     $new = $pow->getNew();

     $newAr = $new->val();

     $get = $prov->getAll($newAr['providerId']);

     $getAr = $get->val();

     $img = $getAr['image'];
     $name = $getAr['provider'];
     $desc = $getAr['description'];
     $zip = $getAr['zip'];
     $web = $getAr['link'];
     if($zip==0){
      $zip = "Unavailable"; 
     }

    print_r($getAr);



  }
  else{
   print 'fail!'; 
  }
    }

//catch exception
catch(Exception $e)
  {
  echo 'Message: ' .$e->getMessage();
  }



?>

//类战俘

require_once('clsSql.php');
require_once('clsResult.php');
include_once('/hermes/web07/b1323/moo.madisoncountyliterac/assets/includes/db.php');    
class POW{
    public function getNew(){
        //instantiate the sql class
        $SQL=new sql();                     
        //Run a query - Result is automatically stored in the class

        $sel = "SELECT providerId
                FROM litProviders
                WHERE image != ''
                ORDER BY RAND()
                LIMIT 1";

        $q=$SQL->query($sel);

        return $q;
    }


}

//类提供者

require_once('clsSql.php');
require_once('clsResult.php');
include_once('/hermes/web07/b1323/moo.madisoncountyliterac/assets/includes/db.php');
class Providers{    
    public function getAll($where=""){
        if($where == ""){
            $getAllQuery = "SELECT * FROM litProviders";
        }
        else{
            $getAllQuery = "SELECT * FROM litProviders WHERE providerId = '".$where."'";
        }       
        //instantiate the sql class
        $SQL=new sql();                 
        //Run a query - Result is automatically stored in the class
        $q=$SQL->query($getAllQuery);
        return $q;
    }

    public function submit($id="", $provider, $description, $zip, $image, $link){

        if($id != ""){
            //update
            $query = "UPDATE litProviders SET provider = '".$provider."', description = '".$description."', zip = '".$zip."', image = '".$image."', link = '".$link."'
                      WHERE providerId = '".$id."' ";

            $message = "The provider has been updated.";
        }
        else{
            //insert    
            $newid = md5(uniqid());

            $query = "INSERT INTO litProviders 
                      VALUES ('".$newid."','".$provider."','".$description."','".$zip."','".$image."', '".$link."')";

            $message = "You have added a new provider.";                          
        }
        //instantiate the sql class
        $SQL=new sql();                 
        //Run a query - Result is automatically stored in the class
        $q=$SQL->query($query);

        return $message;

    }
    public function delete($id=""){
        if($id !=""){
            $delQuery = "DELETE FROM litProviders WHERE providerId = '".$id."'";    
            //instantiate the sql class
            $SQL=new sql();                     
            //Run a query - Result is automatically stored in the class
            $q=$SQL->query($delQuery);
            if($q){
                return true;    
            }
            else{
                return false;   
            }
        }
        else{
            return "No ID was provided for deletion.";  
        }
    }
}

【问题讨论】:

  • 下面的分号是什么 print $web;在做什么?
  • 没什么。那是一根粗大的手指。生病删除它没有影响。

标签: php mysql


【解决方案1】:

我遇到了同样的问题。

我不知道确切的原因或你的问题,但我会告诉你我过去的情况:

我创建了一个 .inc 文件来连接数据库,所以我只会发布我真正实现它的代码:

require"../References/connection.inc";
$con=connect();
if(@ mysql_select_db($dbname,$con))showerror();

此代码在我的页面上删除了“错误 0:”消息。我写的其他页面没有显示这个,所以我注意到我忘记将if() 的内部文本括在另一组括号中并否定它。

工作代码(没有“错误 0:”消息)是:

require"../References/connection.inc";
$con=connect();
if(!(@ mysql_select_db($dbname,$con)))showerror();

【讨论】:

  • 写成@mysql_select_db($dbname,$con) or showerror();比较漂亮
  • 我永远不会知道问题出在哪里。时间太长了,我把所有东西都撕开了,让它发挥作用。我的 SQL 连接类中可能有类似的东西。
【解决方案2】:

如果您不打印除变量之外的其他内容来识别它们,那么打印变量是没有用的。

你应该改为

print_r(array(
    "thing" => $thing,
    "stuff" => $stuff,
    "dwarf" => $dwarf,
));

【讨论】:

  • 我同意。我有点生气,开始忘记一些基本原则。我改了。
  • 现在你得到了什么输出?
  • 什么都没有。它没有产生任何影响。我没有得到结果集。
  • 如果我按程序显示数据,它可以工作。所以连接很好。
  • 尝试在包含之前回显一些内容
【解决方案3】:

我也出现了同样的错误,原来是因为选择数据库时缺少第二个(可选)连接参数。

ex(错误):mysql_select_db($dbname)

例如:(固定):mysql_select_db($dbname,$con)

【讨论】:

    最近更新 更多