I tried to simplify this as much as possible just to understand what's happening but it's still not working. It doesn't show any errors, but nothing gets added to database.
The bootstrap file:
class Connection {
public static function make($config){
return new PDO(
$config['connection'].';dbname='.$config['name'],
$config['username'], $config['password'], $config['options']
);
}
}
class QueryBuilder {
protected $pdo;
public function __construct($pdo){
$this->pdo = $pdo;
}
public function insert($table, $paramater, $value){
$statement = $this->pdo->prepare("insert into $table ($paramater) values($value)");
$statement->execute();
}
}
return new QueryBuilder(Connection::make($config['database']));
Other file after post request:
$query = require 'bootstrap.php';
$query->test('todos', 'description', 'lorem ipsum');
My $config
array is this
return [
'database' => [
'name' => 'mytodo',
'username' => 'root',
'password' => '',
'connection' => 'mysql:host=ip',
'options' => [ ]
]
];