Recently started to understand the PLO and was immediately faced with the problem
Fatal error: Uncaught Error: Call to undefined function add_in_db() in E:\OSPanel\domains\tutorial\index.php:7 Stack trace: #0 {main} thrown in E:\OSPanel\domains\tutorial\index.php on line 7
Here is the code index.php
<?php
spl_autoload_register(function($className){
require_once __DIR__ . '/src/' . $className . '.php';
});
$add = new Project\Model\Task\BD();
var_dump(add_in_db());
Here the class file BD.php
<?php
namespace Project\Model\Task;
class BD{
public $pdo;
public function add_in_db($task, $table)
{
$this->pdo = new PDO('mysql:host=localhost; dbname=listask', 'root', ");
$query = $pdo->prepare("INSERT INTO $table(task) VALUES(?)");
$query->execute([$task]);
}
public function delete_from_db($id)
{
$query = $pdo->prepare("DELETE FROM tasks WHERE id = ? ");
$query->execute([$id]);
}
}
What's the problem? And how to solve it?
UPD: TC, it appears, changed the question. Then I apologize to meet. - Pablo_Parisian commented on April 19th 20 at 12:56