Why Connecting using include once is failing with pdo?
When I connect to the database including a connection page it gave me an error, but when I put the connecting code in and I remove include I do not get errors. What might be the problem?
Error Fatal error: Call to a member function prepare() on a non-object in C:\wamp\www\tish\A\view.php on line 167
Connecting page:
<?php
function connected_Db(){
try {
$con = new PDO('mysql:host=localhost;dbname=tish_database;charset=utf8','root','');
} catch(PDOException $e){
echo 'Connection failed'.$e->getMessage();
}
}
connected_Db();
?>
the way I include it in other pages:
include_once('pdo.inc.php');
connected_Db();
global $con;