leafsphp / db

🗄 Leaf PHP db module
https://leafphp.dev/modules/db/
6 stars 11 forks source link

Inconsistent connection issues #7

Closed mychidarko closed 1 year ago

mychidarko commented 1 year ago

Db connection + documentation not extensive enough. It needs to cover popular db types like mssql and sqlite

mychidarko commented 1 year ago

Hello is there example how to connect to sqlite? i get error Leaf\Db::connect(): Argument #1 ($host) must be of type string, array given, called in

$app->get("/", function () use($app) {
  $pdo = new PDO("sqlite:".__DIR__."/db.sqlite");
  $stm = $pdo->query('SELECT * FROM ll_User');
  $rows = $stm->fetchAll();

  $db = new Leaf\Db;
  $db->connect([
    'host' => 'sqlite:'.__DIR__.'/db.sqlite',
    'dbtype' => 'sqlite',
    'pdoOptions' => 'sqlite:'.__DIR__.'/db.sqlite'
  ]);

  $users = $db->select('ll_User')->where('id', '1')->fetchAll();

  $app->response()->json(["message" => json_encode($rows)]);
});
mychidarko commented 1 year ago
db()->connect([
  'dbname' => 'db2.sqlite',
  'dbtype' => 'sqlite',
]);
mychidarko commented 1 year ago

Documentation needs to cover this