Answer the question
In order to leave comments, you need to log in
Why is he cursing?
I recently started to understand OOP and immediately ran into 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 index.php code
<?php
spl_autoload_register(function($className){
require_once __DIR__ . '/src//' . $className . '.php';
});
$add = new Project\Model\Task\BD();
var_dump(add_in_db());
<?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]);
}
}
Answer the question
In order to leave comments, you need to log in
An error means that the constant contains an invalid operation. Apparently, we are talking about PD0. Are you sure you need a constant? Then why are you passing the result of some calculations with parameters to it? Maybe it shouldn't be a constant?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question