2 Replies - 212 Views - Last Post: 08 January 2013 - 02:08 PM Rate Topic: -----

#1 Tenderfoot  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 160
  • Joined: 21-March 12

Debugging on a remote server

Posted 08 January 2013 - 12:23 PM

Hey all. I'm running into some trouble with a little program I wrote. The problem is, it works just fine on my machine, but when I upload it to the server, it fails at a certain part. I do not have access to the php.ini file as it is, and so I believe remote debugging is out of the question. So what I resorted to was a bunch of echos, which helped me pinpoint where something's going wrong. The following is the troublesome function:

	function serializeKeyArrayAndSendToDB($receivingUser)
	{
		echo "<br />Entered serializeKeyArray<br />"; //This is successful
		include $_SERVER['DOCUMENT_ROOT'] . '/includes/DB.inc.php';
		$serializedCharacterList = serialize($this->characterList);
		echo "Done serializing characterlist: $serializedCharacterList <br />"; //Successful
		$this->messageID = $this->generateKeyID(); //Generate-a 8 character ID
		echo "MessageID for the keyArray: $this->messageID <br />"; //Successful
		
		//Check whether this ID exists in the database already
		
		try
		{
			echo "Hi.<br />"; //successful 
			$sql = 'SELECT COUNT(*) FROM TranslationKeys WHERE ID = :ID';
			$s = $pdo->prepare($sql);
			$s->bindValue(':ID', $this->messageID);
			$s->execute(); 
			$result = $s->fetchAll(); 
			echo "Am I getting the ID for TranslationKeys at all?<br />"; //This is NOT printed
		        //If there is a matching ID in the database already
			if ($result[0][0] > 0)
			{
				$this->messageID = $this->generateKeyID();
				$this->serializeKeyArrayAndSendToDB(); 
			}
		}
		
		catch (PDOException $e)
		{
			echo "Error message: " . $e->getMessage() . "<br />"; 
		}
		
		try
		{
			$sql = 'INSERT INTO TranslationKeys(ID, keyArray, receivingUserEmail) VALUES(:ID, :serializedKeyArray, :receivingUserEmail)';
			$s = $pdo->prepare($sql); 
			$s->bindValue(':ID', $this->messageID);
			$s->bindValue(':serializedKeyArray', $serializedCharacterList);
			$s->bindValue(':receivingUserEmail', $receivingUser);
			$s->execute(); 
			echo "Here I've attempted to insert into TranslationKeys<br />"; //Fails
		}
		
		catch (PDOException $e)
		{
			echo "Error message: " . $e->getMessage() . "<br />";
			//Handle later
		}
	}



I've added comments for each line I echo, saying whether it was successful or not. It's worth noting that the variable $pdo is the database connection, which I receive via the include on top (from db.inc.php). On the server that file is located in www/includes/db.inc.php, so I believe my include line should be successful. I also use similar code for the connection for the login on the program, and that works just fine. But something fails here and I can't quite put my finger on it.

Is This A Good Question/Topic? 0
  • +

Replies To: Debugging on a remote server

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4332
  • View blog
  • Posts: 12,127
  • Joined: 18-April 07

Re: Debugging on a remote server

Posted 08 January 2013 - 12:36 PM

Well at a quick glance from your code it looks like you might have a problem executing your statement. If it is not reaching your echo about the ID for translationkeys, then I would put an echo in your catch, see if that prints, if it doesn't, check if any of the prepare, bindvalue or execute statements there are returning false. I think you will find one of them is. Might be your execute.

If that is the case, then you can look at your PDOStatement's errorInfo array and see if there is any additional info being saved to tell you what went wrong.

I think you have it pinned, you just need to investigate the statements just before where it fails.

P.S. Usually when it works locally and not remotely it means one of two things... 1) There is a permission in your way 2) There is simply a setting that is different in php.ini (compare them and replicate the changes on your local machine to match the remote and test locally).

:)

This post has been edited by Martyr2: 08 January 2013 - 12:38 PM

Was This Post Helpful? 2
  • +
  • -

#3 Tenderfoot  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 160
  • Joined: 21-March 12

Re: Debugging on a remote server

Posted 08 January 2013 - 02:08 PM

View PostMartyr2, on 08 January 2013 - 12:36 PM, said:

Well at a quick glance from your code it looks like you might have a problem executing your statement. If it is not reaching your echo about the ID for translationkeys, then I would put an echo in your catch, see if that prints, if it doesn't, check if any of the prepare, bindvalue or execute statements there are returning false. I think you will find one of them is. Might be your execute.

If that is the case, then you can look at your PDOStatement's errorInfo array and see if there is any additional info being saved to tell you what went wrong.

I think you have it pinned, you just need to investigate the statements just before where it fails.

P.S. Usually when it works locally and not remotely it means one of two things... 1) There is a permission in your way 2) There is simply a setting that is different in php.ini (compare them and replicate the changes on your local machine to match the remote and test locally).

:)/>


Thanks a lot for your help Martyr, the last paragraph in particular helped me solve this. I don't have access to the php.ini file but I assume it's more strict on including file names. The problem was that I accidentally used include 'DB.inc.php' as opposed to lowercase db.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1