Skip to content

Unable to execute a query from a remote server such as Planetscale #1044

Open
@jcchikikomori

Description

@jcchikikomori

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions