i am getting error : Fatal error: Using $this when not in object context in
line $stmt_edit = $this->conn->prepare('SELECT userName, userEmail, phone FROM tbl_users WHERE userID =:uid');
, i followed this , this
& this and all other google , yahoo links but nothing worked for me, please check below code and help me.
usr
global $DB_con;
error_reporting( ~E_NOTICE );
require_once 'dbconfig.php';
if(isset($_GET['edit_id']) && !empty($_GET['edit_id']))
{
$id = $_GET['edit_id'];
$stmt_edit = $this->conn->prepare('SELECT userName, userEmail, phone FROM tbl_users WHERE userID =:uid');
$stmt_edit->execute(array(':uid'=>$id));
$edit_row = $stmt_edit->fetch(PDO::FETCH_ASSOC);
extract($edit_row);
}
else
{
header("Location: home.php");
}
dbconfig
<?php
$db = isset($_POST['db']) ? $_POST['db'] : '';
class Database
{
private $host = "localhost";
private $db_name = "designer3";
private $username = "root";
private $password = "123456";
public $conn;
public function dbConnection()
{
global $DB_con;
$db = isset($_POST['db']) ? $_POST['db'] : '';
$this->conn = null;
try
{
$this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password);
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $exception)
{
echo "Connection error: " . $exception->getMessage();
}
return $this->conn;
}
}
?>
update
i tried by creating new object un user page, but still it did't worked for me : gave this strange error : Fatal error: Call to a member function prepa‌​re() on a non-object in
code
$oDb=new Database();
$custDb=$oDb->dbConnection();
$custDb->conn->prepare('SELECT userName, userEmail, phone FROM tbl_users WHERE userID =:uid');