PHP 奇怪的错误 "0:"。可能的对象语法问题?

标签 php mysql

我正在尝试将网站从一家托管公司转移到另一家托管公司。我一直使用 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();
  }



?>

//类(class)战俘

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.";  
        }
    }
}

最佳答案

我也遇到了同样的问题。

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

我制作了一个 .inc 文件来连接到数据库,因此我只会发布我真正实现它的代码:

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

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

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

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

关于PHP 奇怪的错误 "0:"。可能的对象语法问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2739375/

相关文章:

php - 无法使用多语言 codeigniter 摆脱 URL 中的默认 Controller

PHP foreach 循环只给出 1 个结果

java - 将 BufferedImage 转换为 Image 数据类型

php - Wordpress 和自定义网站之间的单点登录

php - 如何使用 PHP 从输入框中删除引号?

php - 是否可以在 PHP 函数内部将变量设置为全局变量?

mysql 持有并等待同一个锁

mysql - MariaDB CREATE USER 和 GRANT PERMISSION 对我不起作用

mysql - 使用 JOIN 和 GROUP BY 时出现重复条目

php - 提取 url 的一部分