2010-04-29 41 views
2

我正尝试将网站从一个托管公司转移到另一个托管公司。我一直在使用000webhost,直到客户端托管一个域。现在,客户端拥有他们的域名和托管,使用FatCow.com,我不能为我的生活,调试我的PHP代码。我没有收到任何错误。我有一个成功的数据库连接。如果你程序化地显示数据,它可以工作,但是当我尝试使用我的原始对象时,某些事情正在破裂,而只是返回“0:”。我有所有错误。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(); 
    } 



?> 

//类POW

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

什么是低于打印$网络分号;在做什么? – Jack 2010-04-29 18:21:35

+0

没什么。这是一个胖手指。虐待它删除它没有影响。 – 2010-04-29 18:25:18

回答

1

我有同样的问题。

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

我做的。公司文件,以连接到数据库,所以我将只张贴代码,我真正实现它:

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

该代码在我的页面上放下了“Error 0:”消息。我写的其他页面没有显示此内容,所以我注意到我忘记将if()的内部文本放入另一组括号中,并将其忽略。

工作码(不带“错误0:”消息)是:

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

把它写成'@mysql_select_db($ dbname,$ con)或showerror();' – 2011-06-20 20:03:17

+0

我不会知道问题是什么。这段时间太长了,我把所有的东西都拆开来让它工作。在我的SQL连接类中有这样的机会。 – 2011-06-27 13:51:27

1

这不是有用的,如果你不打印打印变量除了他们之外,承认他们。

而应该

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

我同意。我有点勾起了,开始忘记了一些基本原则。我改变了它。 – 2010-04-29 18:29:23

+0

现在你作为输出得到了什么? – 2010-04-29 18:40:55

+0

什么都没有。它没有产生任何影响。我没有得到结果集。 – 2010-04-29 18:44:03

0

我正在显示的相同的错误,事实证明,这是由于缺少第二(可选)连接参数选择数据库时不包括在内。

EX(错误):mysql_select_db($dbname)

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