Hi. I have been out of the programming game for some time now. I have been told by my website hosting company that they are upgrading the server from PHP4.5 to PHP7. I have been told I can’t use my mysql and to go for PDO. I have been researching this as there is a lot of code to update. What I have got so far is this...

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

define ('HOSTNAME1', '****'); 
define ('USERNAME1', '****');
define ('PASSWORD1', '****');
define ('DATABASE1', '****');

$host = HOSTNAME1;
$user = USERNAME1;
$pass = PASSWORD1;
$MyDB = DATABASE1;

$conn = new PDO("mysql:host=$host; dbname=$MyDB; charset=UTF8", $user, $pass, [
		PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
		PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
		PDO::ATTR_EMULATE_PREPARES   => false,
]);

$Result = Contracts($conn);
$MyRow = $Result->fetch();
echo "Value = " . $MyRow['Venue'];

function Contracts($conn)
{	
	$qList = $conn->query("SELECT * FROM EC_event WHERE ID = 2");
	return $qList;
}
?>

    This is what I am getting
    Notice: Undefined variable: conn in /vhost/vhost15/d/e/s/desmond-otoole.co.uk/www/PDOtest2.php on line 27

    Fatal error: Call to a member function query() on a non-object in /vhost/vhost15/d/e/s/desmond-otoole.co.uk/www/PDOtest2.php on line 27

      I've edited your post to use block-code ``` ... ``` quotes instead of inline ` ` ones. I've also elided the login details that you had. (Incidentally, you might also want to look at const.)

      As for your error: assuming line 27 is $qList = $conn->query("SELECT * FROM EC_event WHERE ID = 2"); I don't see why $conn wouldn't be defined — it's a parameter of the Contracts function. You would get the second error if the database connection failed for whatever reason, but the variable would still be there.

        Sorry. thought I had to place the code between them. I have found that my google chrome was cashing so I renamed it in ftp. It works now. Thanks.

          otuatail Yes; the advantage is that PHP and static analysis tools can do a better job of connecting a constant's use with its definition.

          Yes, the quoting mechanism is a bit unintuitive. Markdown always is because there are so many variations and no-one ever bothers to explain them.

            11 days later

            Where is the rest of this. I can only see a page one. 11 days ago.

            What makes you think there should be more?

              Write a Reply...