after a lot of hours troubleshooting i found that my hoster (hosting2go.nl) does not support PDO::mysql they just dont installd the driver so my Model.php in my MVC framework is screwed. I solved the problems with my database-conection. The problem is that i am completely new to mysqli and justr cant find out how to make my model.php (writen for PDO::mysql) writen for Mysqli (instead of PDO) i hope you guys can help me out... My code:
|ORIGINAL PDO MODEL.PHP|
class Model
{
function __construct()
{
$this->db = new Database;
$this->data = $_POST;
}
public function query( $data = array(), $query){
try{
$result = $this -> db -> prepare($query);
$result->execute($data);
$result = $result->fetchAll(PDO::FETCH_ASSOC);
return $result;
}catch(PDOException $e){
echo $e;
}
}
|My Database-connection|
class Database extends mysqli {
public function __construct() {
parent::__construct("localhost","root","","bartsite");
if (mysqli_connect_error()) {
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
}
}
|This is what i made of my model.php FOR MYSQLI|
class Model
{
function __construct()
{
$this->db = new Database;
$this->data = $_POST;
}
public function query( $data = array(), $query){
try{
echo $query;
$result = $this -> db -> prepare($query);
$result = $this -> db -> query($data);
$result->fetch_all();
//$result->execute($data);
//$result = $result->fetchAll(PDO::FETCH_ASSOC);
}catch(PDOException $e){
echo $e;
}
}
}
|usefull part f the controller|
public function index(){
$data = $this->posts->getAllPosts();
var_dump($data);
$this->view->render("posts/index",$data);
return true;
}
|posts.models.php| class postsModel extends Model {
function __construct()
{
parent::__construct();
}
public function getAllPosts(){
$result = $this->query(
array(),
"SELECT * FROM posts ORDER BY id DESC"
);
return $result;
}