Open
Description
Information
- Version of Medoo: 2.1.4
- Version of PHP: 8.0
- Type of Database (MySQL, MSSQL, SQLite...): MySQL
- System: MacOS
Describe the Problem
Uncaught PDOException near either column name or FROM
Detail Code
The detail code you are using causes the problem.
// Write your PHP code here
use Medoo\Medoo;
public function connect_database(): Medoo
{
$database_properties = [
'type' => $_ENV['DB_TYPE'] ?? 'mysql',
'database' => $_ENV['DB_NAME'],
'host' => $_ENV['DB_HOST'],
'username' => $_ENV['DB_USER'],
'password' => $_ENV['DB_PASS'],
'charset' => $_ENV['DB_CHARSET'] ?? null,
'port' => $_ENV['DB_PORT'] ?? null, // if defined then use, else default
'option' => [
PDO::ATTR_CASE => PDO::CASE_NATURAL,
PDO::MYSQL_ATTR_SSL_CA => '/etc/ssl/cert.pem' // using planetscale as Database server
],
'logging' => true,
];
return new Medoo($database_properties);
}
var_dump($this->connect_database()->debug()->select("user_types", "*")); die();
Expected output
Working query with var_dump()
array(2) { [0]=> array(3) { ["id"]=> int(0) ["user_type"]=> string(5) "admin" ["type_desc"]=> string(14) "Administrators" } [1]=> array(3) { ["id"]=> int(1) ["user_type"]=> string(4) "user" ["type_desc"]=> string(5) "Users" } }
Notes
Working in native implementation
use PDO;
$dsn = "mysql:host={$_ENV['DB_HOST']};dbname={$_ENV['DB_NAME']}";
$options = array(PDO::MYSQL_ATTR_SSL_CA => "/etc/ssl/cert.pem");
$pdo = new PDO($dsn, $_ENV["DB_USER"], $_ENV["DB_PASS"], $options);
$query = $pdo->prepare('SELECT * FROM `user_types`');
$query->execute();
$result = $query->fetchAll(PDO::FETCH_ASSOC);
var_dump($result); die();
Metadata
Metadata
Assignees
Labels
No labels