1. Go to this page and download the library: Download comphp/database library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
comphp / database example snippets
use Neuron\Database\DatabaseManager;
use Neuron\Database\Drivers\MysqlDatabaseDriver;
use Neuron\Extensibility\ExtensionStore;
use Neuron\Extensibility\InstantiatorInterface;
use Psr\Log\LoggerInterface;
use Psr\EventDispatcher\EventDispatcherInterface;
// Imagine these are created or injected by your DI container
/** @var LoggerInterface $logger */
/** @var InstantiatorInterface $instantiator */
/** @var EventDispatcherInterface $eventDispatcher */
$extensions = new ExtensionStore($instantiator, $logger, $eventDispatcher);
$database = new DatabaseManager($logger, $extensions, $eventDispatcher);
// Create a new connection
$database->connect('_default_', MysqlDatabaseDriver::class, [
'database' => 'my_database',
'host' => 'localhost',
'username' => 'root',
'password' => 'root',
]);
// Fetch rows
$rows = $database->fetchAll('SELECT * FROM users');
foreach ($rows as $row) {
echo "User: " . $row['name'] . "\n";
}
$database->enableProfiling();
// All queries now dispatch QueryExecutedEvent with timing info
use Neuron\Database\AbstractDatabaseDriver;
use Neuron\Database\DatabaseDriver;
use Neuron\Database\DatabaseDriverInterface;
#[DatabaseDriver]
class YourCustomDriver extends AbstractDatabaseDriver implements DatabaseDriverInterface
{
// implement count(), fetchOne(), fetchAll(), etc.
}
// Then register
$extensions->getRegistry()->register(DatabaseDriver::class, YourCustomDriver::class);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.