Bardzo prosze o pomoc w debugowaniu PHP scriptu - chodzi o połączenie z bażą danych. Oto init.php
<?php
$dbConfig = Config::getInstance()->get("db");
$db = new PDO(
"mysql:host=127.0.0.1;dbname=bookstore",
$dbConfig["user"],
$dbConfig["password"]
);
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$rows = $db->query("SELECT * FROM book ORDER BY title");
foreach ($rows as $row) {
var_dump($row);
}
$query = <<<SQL
INSERT INTO book (isbn, title, author, price)
VALUES ("9788187981954", "Peter Pan", "J.M. Barrie", 2.34)
SQL;
$result = $db->exec($query);
var_dump($result);
$error = $db->errorInfo()[2];
var_dump($error);
$query2="SELECT * FROM book WHERE author=:author";
$statement = $db->prepare($query);
$statement->bindValue("author", "George Orwell");
$statement->execute();
$rows = $statement->fetchAll();
var_dump($rows);
?>
Config.php
<?php
namespace Bookstore\Utils;
use Bookstore\Utils\NotFoundException;
class Config {
private $data;
private static $instance;
public function __construct() {
$json = file_get_contents(__DIR__ . "/../../config/app.json");
$this->data = json_decode($json, true);
//self::$data = json_decode($json, true);
}
public static function getInstance() {
if (self::$instance==null) {
self::$instance = new Config();
}
return self::$instance;
}
public static function get($key) {
if (!isset($this->data[$key])) {
throw new NotFoundException("Key $key not in config.");
}
return $this->data[$key];
}
}
?>
Bardzo chciaabym wiedzieć dlaczego podczas odświeżania localhost/init.php pisze "class Config not found" pomimo że wszystko sie zgadza