代码之家  ›  专栏  ›  技术社区  ›  Michael Stone

php奇怪错误“0:”。可能的对象语法问题?

  •  2
  • Michael Stone  · 技术社区  · 15 年前

    我正在尝试将一个网站从一个托管公司转移到另一个托管公司。在客户端拥有主机和域之前,我一直在使用000webhost。既然客户端已经有了自己的域名和主机,使用fatcow.com,我一辈子都无法调试我的php代码。我没有任何错误。我有一个成功的数据库连接。如果您按程序显示数据,它会工作,但当我尝试使用原始对象时,某些内容会中断并返回“0:”。我犯了所有的错误。

    在站点工作的旧服务器上:

    php版本5.2.11

    MySQL版本:5.0.81

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

    php版本5.2.12

    MySQL 5.0.32版

    我已经设置了一个测试页来测试db连接变量的输出。

    以下是我的代码:

    <?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.";  
            }
        }
    }
    
    3 回复  |  直到 12 年前
        1
  •  2
  •   Bo Persson Touseef    14 年前

    我也有同样的问题。

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

    我制作了一个连接到数据库的.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();
    
        2
  •  1
  •   o0'.    15 年前

    如果不打印变量之外的内容来识别它们,则打印变量是没有用处的。

    你应该改

    print_r(array(
        "thing" => $thing,
        "stuff" => $stuff,
        "dwarf" => $dwarf,
    ));
    
        3
  •  0
  •   sailtheworld    12 年前

    我显示了同样的错误,结果发现这是因为在选择数据库时缺少第二个(可选)连接参数。

    前(错误): mysql_select_db($dbname)

    EX:(固定): mysql_select_db($dbname,$con)

    推荐文章