PHP code example of imphp / database

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

    

imphp / database example snippets




...

use im\database\mysqli\Connection;

$id = 10;
$conn = new Connection("localhost", "My_DB", "user", "MyPassw");
$result = $conn->enquire("SELECT FROM tbl WHERE id=%i", $id);
$rownum = $result->fetchColumn("row_num", true);

$affected = $conn->execute("DELETE FROM tbl WHERE row_num=%i", $rownum);

if ($affected > 0) {
    echo "Success!";
}

$conn->close();

use im\database\sqlite3\Connection;

$conn = new Connection("My_DB.db");
$stmt = $conn->stmt("UPDATE tbl SET role=%s WHERE id=%i");
$users = [
    10 => "admin",
    12 => "user",
    25 => "admin"
];

foreach ($users as $id => $role) {
    $stmt->execute($role, $id);
}

$stmt->close();
$conn->close();