PHP Strange error "0:". Possible object syntax problem?

I am trying to migrate a site from one hosting company to another. I used 000webhost until the client had a hosting and domain. Now that the client has their domain and hosting using FatCow.com, I can't debug my PHP code for the rest of my life. I am not getting any errors. I have a successful DB connection. If you display data procedurally, it works, but when I try to use my original objects, something breaks and just returns "0:". I have all the errors.

On the old server where the site was running:

PHP Version 5.2.11

MySQL version: 5.0.81

On the new server where I get "0:":

PHP Version 5.2.12

MySQL version 5.0.32

I have set up a test page to test only the output of variables using a DB connection.

Below is my code:

<?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 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;
    }


}

      

// Class providers

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


a source to share


3 answers


I had the same problem.

I don't know the exact cause or your problem, but I will tell you about my past situation:

I made a .inc file to connect to the database, so I'll only post the code where I actually implemented it:

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

      



This code dropped the "Error 0:" message on my page. Other pages I wrote didn't display this, so I noticed that I forgot to wrap the inner text if()

in another group of brackets and deny it.

Working code (no "Error 0:" message):

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

      

+1


a source


It is not useful to print variables unless you print something beyond them to recognize them.

Instead, you should



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

      

+1


a source


I had the same error as displayed, it turned out to be due to the missing second (optional) connection parameter when selecting the database.

ex (error): mysql_select_db($dbname)

ex: (fixed): mysql_select_db($dbname,$con)

0


a source







All Articles