Answer the question
In order to leave comments, you need to log in
How to implement connection interface to sqlite?
Good afternoon, ladies and gentlemen.
I'm trying to implement connection to sqlite database and make create in it.
Here is such a task, it is on OOP that you need to inherit the interface and implement it in the class.
Implement the App\DDLManagerInterface interface in the App\DDLManager
DDLManagerInterface class
<?php
namespace App;
interface DDLManagerInterface
{
public function __construct($dsn, $user = null, $pass = null);
public function createTable($table, array $params);
}
<?php
namespace App;
class DDLManager implements DDLManagerInterface
{
private $pdo;
public function __construct($dsn, $user = null, $pass = null)
{
}
public function createTable($table, array $params)
{
}
public function getConnection()
{
return $this->pdo;
}
}
//Пример использования:
$dsn = 'sqlite::memory:';
$ddl = new DDLManager($dsn);
$ddl->createTable('users', [
'id' => 'integer',
'name' => 'string'
]);
Получившийся запрос в базу:
CREATE TABLE users (
id integer,
name string
);
Answer the question
In order to leave comments, you need to log in
I didn’t understand about paths and what doesn’t work, but a couple of comments regarding OOP:
1. I would not specify a constructor in the interface. Because it will interfere with genericity if you want to extend the functionality of the common class in the future.
2. The DDLManager itself must extend the functionality of the abstract class. Again, to the issue of extensibility and universality.
3. The final driver itself should contain only specific methods and class variables.
Here is an example of an abstract class https://github.com/Falseclock/dbd-php/blob/master/...
Here is the interface itself https://github.com/Falseclock/dbd-php/blob/master/...
And here is the driver https://github.com/Falseclock/dbd-php/blob/master/...
Thanks to its versatility, without any problems, in addition to the SQL driver, I also created the OData driver
https://github.com/Falseclock/dbd-php/blob/master/...
And based on it, the 1C data connection driver https://github .com/Falseclock/dbd-php/blob/master/...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question