I have copied the PDO connection script directly from the php.net documentation, however, it fails to work, because it gets this error.
<?php
global $pdo = new PDO('mysql:host=localhost;dbname=pionear', "root", "");
?>
I have copied the PDO connection script directly from the php.net documentation, however, it fails to work, because it gets this error.
<?php
global $pdo = new PDO('mysql:host=localhost;dbname=pionear', "root", "");
?>
You cannot declare a variable in the global scope like that. You have to declare it as a normal variable and than access it through global
(e.g. in a function):
$pdo = new PDO('mysql:host=localhost;dbname=pionear', "root", "");
function something() {
global $pdo;
$pdo->doSometing();
}
something();
You can check the documentation on the global
keyword for more information. If you do not want to use the global
keyword you can instead use $GLOBALS
(which is a 'superglobal', thus no need to do global $pdo;
).