PHP code example of profmugomes / miphantdb

1. Go to this page and download the library: Download profmugomes/miphantdb 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/ */

    

profmugomes / miphantdb example snippets


use MiPhantDB\database;

$db = new database([
    'server'   => 'localhost',
    'username' => 'root',
    'password' => '',
    'database' => 'meubanco'
], true); // true ativa o modo sandbox (logs em tela)

use MiPhantDB\select;

$select = new select([
    'server'   => 'localhost',
    'username' => 'root',
    'password' => '',
    'database' => 'meubanco'
]);

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

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

$select->close();

$select->table('users')
    ->where('id', '?')->prepared(1, 'i')
    ->select();

$select->getResult();

$row = $select->fetch();

use MiPhantDB\insert;

$insert = new insert($dbConfig);

$insert->table('users')
    ->add('name', '?')
    ->add('email', '?')
    ->prepared('Exemplo', 's')
    ->prepared('[email protected]', 's')
    ->insert();

$id = $insert->idinsert();

use MiPhantDB\update;

$update = new update($dbConfig);

$update
    ->table('users')
    ->add('email', '?')
    ->where('id', '?')
    ->prepared('[email protected]', 's')
    ->prepared(1, 'i')
    ->update();

use MiPhantDB\delete;

$delete = new delete($dbConfig);

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

use MiPhantDB\table;

$table = new table($dbConfig);

$table->table('users')
    ->int()->autoIncrement()->primaryKey()->add('id')
    ->varcharSize(100)->add('name')
    ->varcharSize(150)->add('email')
    ->engine('InnoDB')
    ->create();

$table
    ->table('users')
    ->varcharSize(255)->add('bio')
    ->alter(table::ALTER_ADD);

if (!$table->columnExists('email')) {
    // criar coluna
}

$select->close();

$select->table('users')
    ->where('status', 'ativo')
    ->select();

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

$select->close();