Error: Call to a member function execute() on string in C:\OpenServer\domains\study\index.php:30 Stack trace: #0 {main} thrown in C:\OpenServer\domains\study\index.php on line 30
Код: <!DCOTYPE html>
<head>
<title>Test</title>
</head>
<body>
<form name="text" action="" method="POST">
<input name = "message" type="text">
<input name = "button" type="submit">
</form>
<?php
$message = $_POST['message'];
$db_host = "localhost";
$db_user = "postgres";
$db_password = "";
$db_base = 'postgres';
$db_table = "text";
try {
$db = new PDO("pgsql:host=$db_host;dbname=$db_base", $db_user, $db_password);
$db->exec("set names utf8");
} catch (PDOException $e) {
print "Ошибка!: " . $e->getMessage() . "<br/>";
}
$data = array('message' => $message);
$query = ("INSERT INTO $db_table (message) values (:message)");
$query->execute($data);
?>
</body>
https://t.me/phpGeeksJunior
Поставь слеш перед PDO, вот так \PDO
Обсуждают сегодня