Search by

profmugomes / miphantdblite

profmugomes

Crie tabelas e consulte, adicione, altere e exclua registros do SQLite3.

Package info

github.com/profmugomes/miphantdblite

pkg:composer/profmugomes/miphantdblite

Fund package maintenance!

profmugomes

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

5.0.0 2026-09-27 02:44 UTC

This package is auto-updated.

Last update: 2026-10-23 04:58:38 UTC


README

MiPhantDBLite é uma biblioteca leve, minimalista e fluente escrita em PHP para trabalhar com SQLite3, focada em simplicidade, baixo consumo de recursos e controle total do SQL gerado.

Sem ORM pesado, sem abstrações mágicas, apenas SQL claro, previsível e encadeável.

✨ Características

  • Abstração leve sobre SQLite3
  • API fluente (encadeável)
  • Suporte a SELECT, INSERT, UPDATE, DELETE
  • Suporte opcional a prepared statements
  • Construção dinâmica de WHERE, ORDER BY e LIMIT
  • Suporte a LIKE, IN, AND, OR
  • Criação de tabelas via código
  • Zero dependências externas
  • Compatível com PHP 8.4 ou superior

📦 Instalação

Via Composer (recomendado)

composer require profmugomes/miphantdblite

Manual

Copie os arquivos da pasta MiPhantDBLite para o seu projeto e utilize require ou autoload.

🔌 Conexão com o banco SQLite

use MiPhantDBLite\database;

$db = new database(
    'database.sqlite',
    true // modo sandbox (erros exibidos na tela)
);

Também é possível usar opções de abertura:

$db = new database(
    'database.sqlite',
    false,
    database::READWRITE | database::CREATEONLY
);

📖 SELECT

use MiPhantDBLite\select;

$select = new select('database.sqlite');

$select->table('users')
    ->column('id')
    ->column('name')
    ->where('status', 'ativo')
    ->order('name')
    ->limit(0, 10)
    ->select();

while ($row = $select->fetch()) {
    echo $row['name'];
}

$select->close();

🔐 Prepared Statements

$select->activatePrepared()
    ->table('users')
    ->where('id', 1)
    ->select();

$row = $select->fetch();
$select->close();
  • Evita SQL Injection
  • Ideal para dados dinâmicos
  • Ativado explicitamente via activatePrepared()

➕ INSERT

use MiPhantDBLite\insert;

$insert = new insert('database.sqlite');

$insert->activatePrepared()
    ->table('users')
    ->insertValue('name', 'João')
    ->insertValue('email', 'joao@email.com')
    ->insert();

$id = $insert->idInsert();
$insert->close();

✏️ UPDATE

use MiPhantDBLite\update;

$update = new update('database.sqlite');

$update->activatePrepared()
    ->table('users')
    ->updateValue('email', 'novo@email.com')
    ->where('id', 1)
    ->update();

$update->close();

❌ DELETE

use MiPhantDBLite\delete;

$delete = new delete('database.sqlite');

$delete->table('users')
    ->where('id', 1)
    ->delete();

$delete->close();

🧱 Criação de tabelas

use MiPhantDBLite\table;

$table = new table('database.sqlite');

$table->table('users')
    ->setInt()->primaryKey()->autoIncrement()->insertColumn('id')
    ->insertColumn('name')
    ->insertColumn('email')
    ->create();

$table->close();

🔒 Encerrando a conexão (close)

$db->close();

O que o close() faz?

  • Libera resultados ativos
  • Finaliza prepared statements (quando usados)
  • Fecha corretamente a conexão SQLite
  • Evita vazamento de recursos em scripts longos ou CLIs

💡 Boa prática: Embora o PHP finalize a conexão ao fim do script, o uso explícito de close() é altamente recomendado em aplicações CLI, loops e processos persistentes.

🧠 Outras Informações

  • SQLite continua sendo SQLite
  • Sem ORM pesado
  • Sem reflexão ou proxies mágicos
  • SQL previsível e fácil de depurar
  • Ideal para projetos pequenos, locais ou embarcados

👤 Autor

Murilo Gomes

🔗 https://www.profmugomes.com.br

📺 https://youtube.com/@profmugomes

🤝 Support

License

Copyright (c) 2025-2026 Murilo Gomes <profmugomes.com.br>. All Rights Reserved.

This project is licensed under the PolyForm Perimeter License 1.0.1.

Summary

This software is available for commercial and noncommercial use, subject to the terms of the PolyForm Perimeter License 1.0.1.

You may:

  • ✔ Use the software for commercial and noncommercial purposes.
  • ✔ Inspect and study the source code.
  • ✔ Modify the software.
  • ✔ Create derivative works based on the software.
  • ✔ Redistribute the software and permitted modifications.

You may not:

  • ✖ Provide a product that competes with the software.

See the full license terms at LICENSE.md.

This summary is provided for convenience only and does not replace or modify the full license terms.