Why does this getMessages product fatal error?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Why does this getMessages product fatal error?

Post 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);
}

?>
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Why does this getMessages product fatal error?

Post by Celauran »

Because the method is getMessage.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Why does this getMessages product fatal error?

Post by simonmlewis »

Blast it. How did that 's' get in there. Thanks a lot.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Why does this getMessages product fatal error?

Post 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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Why does this getMessages product fatal error?

Post 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.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Why does this getMessages product fatal error?

Post by simonmlewis »

I have no idea. How do I do that - or should I ask the hosts for that?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Why does this getMessages product fatal error?

Post by simonmlewis »

They'd given me the wrong IP address for the database. Muppets!
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Why does this getMessages product fatal error?

Post 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.
Post Reply