I'm attempting to upgrade my website to the newest, or at least a newer, version of PHP. Through out my site I receive Internal Server Error messages. Some are consistent and occur every time you access a page. Others are intermittent even though the same actions were taken. I am trying to solve at least one of the errors in hopes of gaining a foothold in solving all the rest.
Code that consistently produces the Internal Server Error:
try {
global $dbCon;
$stmt = $dbCon->prepare("SELECT pdf_template, ai_template, id_template, img_template FROM products WHERE sku=:s ");
$stmt->execute(array(':s' => $sku)); //Failure occurs on this line
$result = $stmt->fetch(PDO::FETCH_ASSOC); //This is never reached
//$stmt->bindValue(':sku',$sku,PDO::PARAM_STR);//Attempted alternate form of binding
//$stmt->execute(); //Alternate binding still failed here
} catch (PDOException $e) {
$logger->warn("Database call failed, was unable to gather product templates", "pricing modal", "sku: $sku");
}
As you can see by my comment, the line $stmt->execute(array(':s' => $sku));
is consistently the culprit. If it is commented out, page still loads. More specifically, if I put $stmt->execute();
the statement executes and the page still loads (minus DB required content of course). So it seems that during PHP's attempt to bind the variables to the prepared statement there is a failure. This also applies to bindValue()
. Anytime a value is bound previously execute fails.
I have tried many ways to get some type of output in the logs. For example at the top of the page
error_reporting(E_ALL);
ini_set( 'display_errors','1');
ini_set("log_errors", 1);
ini_set("error_log", "/tmp/php-error.log");
error_log( "Hello, errors!" );
In the .htaccess:
php_flag log_errors on
php_value error_log /tmp/php-error.log
I have tried various permutations of the previous code trying to produce an error in the log file. Yes, some of it is redundant, I was getting desperate for an answer. Yes, 'Hello, errors!" does appear in the log file.
The cause of all of this: Website works wonderfully on PHP 5.3. It is the version it was developed in. (I know, should of developed it on the newer version. I have logistic reasons that were previously out of my control) When I bump the version up to 5.4 or 5.5 I get the internal server error. Can someone provide some insight and deeper knowledge about this topic. Thank you very much.
EDIT: $dbCon declaration:
try{
$dbCon = new PDO('mysql:host=mysql.example.com;dbname=db_sandbox',$db_user,$db_password, array(
PDO::ATTR_PERSISTENT => true,
PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
} catch( PDOException $e ) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
@rjdown I did that before, and I just did it again with an actual fix showing up. It was to remove ob_start()
because headers were not being sent in the correct order. That fixed that page.
Now I'm still getting Internal server error somewhere else. Different error now. Involving glibc error that is specific to my server and beyond the scope of this particular question.