Hey I am practicing login system with oop from codecourse.Till the database connectivity everything moving in right direction but when i try to run query execute return false.
class DB{
private static $_instance = null;
private $_pdo,
$_query,
$_error=false,
$_results,
$_count=0;
private function __construct(){
try{
$this->_pdo = new PDO(
"mysql:".Config::get("mysql/host").";
dbname=".Config::get("mysql/db").";
port=".Config::get("mysql/port")."\",\""
.Config::get("mysql/username")."\",\""
.Config::get("mysql/password")."\"");
}catch(Exception $e){
echo $e->getMessage();
exit();
}
}
public static function get_instance(){
if(!isset(self::$_instance)){
self::$_instance = new DB();
}
return self::$_instance;
}
public function query($sql,$params = array()){
$this->_error = false;
if($this->_query = $this->_pdo->prepare($sql)){
$x=1;
if(count($params)){
foreach ($params as $param) {
$this->_query->bindValue($x,$param);
$x++;
}
}
if($this->_query->execute()){ //here i m geeting value as false
echo "success";
$this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ);
$this->_count = $this->_query->rowCount();
}else{
echo "error";
$this->_error = true;
}
}
}
}
Here is my index.php from where i passing query in to function in class DB.
$user = DB::get_instance()->query("Select * from users");