Reputation: 118
i have a DB helper and code is in this way:
<?php
namespace App\Business;
use DB;
Class DBHelper{
private function dbConnectionInfo()
{
//$results = DB::select('Select UserName from user_master');
//return "fetchUserLocation success". json_encode($results) ;
$pdo_db = DB::connection()->getPdo() ;
$pdo_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $pdo_db;
}
function executeResultSet($DBQuery)
{
$pdo_object = DBHelper :: dbConnectionInfo();
$stmt = $pdo_object->prepare($DBQuery);
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $results;
}
function dbConnection()
{
return DBHelper :: dbConnectionInfo();
}
}
?>
When i call return "fetchUserLocation success". json_encode($results) ; it executed that means DB connection works properly but when i call the function error : Class 'App\Business\PDO' not found How can i use PDO in this code. please suggest
Upvotes: 0
Views: 9418
Reputation: 419
this is your problem, this PDO:: does not exist, you are doing the raw pdo thing instead of the one your dependencies. this is what you should do
$results = $stmt->fetchAll($pdo_object::FETCH_ASSOC);
Upvotes: 0
Reputation: 420
You'll need to:
Install PDO support. Enable PDO in your PHP configuration. This can be done by adding the following:
extension=pdo.so
extension=pdo_mysql.so
to your php.ini
file.
Upvotes: 0
Reputation: 2569
Write \PDO instead of PDO, because it is searching PDO inside your namespace instead of searching 'PDO' in the root namespace.
Upvotes: 2