Page 1 of 1

Why does this getMessages product fatal error?

Posted: Wed Jan 06, 2016 10:21 am
by simonmlewis
When I use this, I get Fatal Error messages. I really don't know why. It could be the server's error setup, to catch tiny things.

[text][Wed Jan 06 16:04:54 2016] [warn] [client 79.**.120.150] mod_fcgid: stderr: PHP Fatal error: Call to undefined method PDOException::getMessages() in /home/plat-linnas01/s/sandbox.website.co.uk/user/htdocs/dbconn.php on line 20[/text]

Code: Select all

<?php
if (!defined('DBUSER')) {
define('DBHOST', '***ip here ***');
define('DBUSER', 'username');
define('DBPASS', 'password');
define('DBNAME', 'databasename');
}

$sqlconn = mysql_connect(DBHOST, DBUSER, DBPASS);
if ($sqlconn) {
        mysql_select_db(DBNAME);
}

try {
    $pdo = new PDO('mysql:host=' . DBHOST . ';dbname=' . DBNAME, DBUSER, DBPASS);
} catch (Exception $e) {
        $to = "emailaddress";
        $subject =  "DB Down";
        $headers = "From: info@website.co.uk";
        $body = "DB Error: " . $e->getMessages();

        mail ($to, $subject, $body, $headers);
}

?>

Re: Why does this getMessages product fatal error?

Posted: Wed Jan 06, 2016 10:36 am
by Celauran
Because the method is getMessage.

Re: Why does this getMessages product fatal error?

Posted: Wed Jan 06, 2016 10:38 am
by simonmlewis
Blast it. How did that 's' get in there. Thanks a lot.

Re: Why does this getMessages product fatal error?

Posted: Wed Jan 06, 2016 11:09 am
by simonmlewis
This new server is doing my head in.

It's erroring on this saying:
[text][Wed Jan 06 16:58:00 2016] [warn] [client 79.**.120.150] mod_fcgid: stderr: PHP Notice: Undefined variable: pdo in /home/plat-linnas01/s/sandbox.site.co.uk/user/htdocs/index.php on line 71, referer: http://sandbox.site.co.uk/
[Wed Jan 06 16:58:00 2016] [warn] [client 79.**.120.150] mod_fcgid: stderr: PHP Fatal error: Call to a member function prepare() on null in /home/plat-linnas01/s/sandbox.site.co.uk/user/htdocs/index.php on line 71, referer: http://sandbox.site.co.uk/[/text]

Code: Select all

$query = "SELECT * FROM seo WHERE page =:page";
$result = $pdo->prepare($query);
$result->execute(array(':page' => $page));
while ($row = $result->fetch(PDO::FETCH_OBJ)) 
      {
  echo "<title>$row->titletag</title>
<meta http-equiv=\"content-language\" content=\"EN-US\" />
<META NAME=\"country\" CONTENT=\"United States (USA)\">
<meta name=\"description\" content=\"$row->metadescription.\" />
<meta name=\"keywords\" content=\"$row->metakeywords\" />";
  }
I get no such errors locally.

Re: Why does this getMessages product fatal error?

Posted: Wed Jan 06, 2016 11:16 am
by Celauran
Have you checked that the PDO module is available on the server? You might want to add some logging to that catch block rather than relying on email.

Re: Why does this getMessages product fatal error?

Posted: Wed Jan 06, 2016 11:18 am
by simonmlewis
I have no idea. How do I do that - or should I ask the hosts for that?

Re: Why does this getMessages product fatal error?

Posted: Wed Jan 06, 2016 11:23 am
by simonmlewis
They'd given me the wrong IP address for the database. Muppets!

Re: Why does this getMessages product fatal error?

Posted: Wed Jan 06, 2016 11:30 am
by Celauran
simonmlewis wrote:I have no idea. How do I do that - or should I ask the hosts for that?
For the record, phpinfo() will tell you that.