-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Description
Hi, I get an error with connecting to the database! It says
Warning: PDO::prepare(): SQLSTATE[00000]: No error: PDO constructor was not called in /customers/a/d/5/domain.com/httpd.www/mvc/app/core/Model.php on line 63 Fatal error: Call to a member function execute() on null in /customers/a/d/5/domain.com/httpd.www/mvc/app/core/Model.php on line 64
Do you know why this is?
I have created a DB and going to the URL domain.com/users/profile/1 which then gives the error.
Here is the controller code:
<?php if (!defined('BASE_PATH')) exit('No direct script access allowed');
class Users extends Controller
{
public function __construct()
{
$this->load_helper(['view']);
}
public function index()
{
$this->view('blog/index');
}
// Show our User Profile report
public function profile($user_id)
{
// Load the User Model so that we can query the database
$user = $this->model('User');
// Get this user
$bind = [':id' => $user_id];
$data = $user->select('jh_users','id = :id', $bind);
// Load the View passing to it the Users information as $data.
$this->view('users/profile', $data);
}
public function phpinfo()
{
echo phpinfo();
}
}
Here is the model code:
<?php if (!defined('BASE_PATH')) exit('No direct script access allowed');
class User extends Model
{
public $fname;
public $lname;
private $db;
public function __construct()
{
$this->db = new Model();
}
public function getName()
{
return $this->fname . ' ' . $this->lname;
}
public function getUsers()
{
/* get all users */
$results = $this->db->select("jh_users");
}
public function getMaleUsers()
{
/* get a specific user */
$results = $this->db->select("jh_users", "Gender = 'male'");
}
public function addUser($fname, $lname, $age, $gender)
{
/* add a new user */
$data = [
"fname" => $fname,
"lname" => $lname,
"age" => $age,
"gender" => $gender
];
$this->db->insert("jh_users", $data);
}
}
What am i doing wrong or is it database error?
Once all these minor errors are gone i will be on my way and create a awesome application!
Thanks in advance!
Metadata
Metadata
Assignees
Labels
No labels