PHP code example of jonathanbak / mysqlilib

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

    

jonathanbak / mysqlilib example snippets


$DB = new MySQLiLib($host, $user, $password, $dbName);
$query = "SELECT * FROM test";
$row = $DB->fetch($query);
var_dump($row);

$query = "SELECT * FROM test WHERE id = ?";
$row = $DB->fetch($query, array(222));
var_dump($row);

$query = "SELECT * FROM test WHERE id = ?";
$rows = array();
while($row = $DB->fetch($query, array(11))){
    $rows[] = $row;
}
var_dump($rows);

$query = "SELECT * FROM test WHERE name LIKE '??%'";
$rows = array();
while($row = $DB->fetch($query, array('테스트'))){
    $rows[] = $row;
}
var_dump($rows);

$query = "INSERT INTO test SET id = ?, reg_date = ?";
$result = $DB->query($query, array(33, date("Y-m-d H:i:s")));
var_dump($result);

$query = "DELETE FROM test SET id = ?";
$result = $DB->query($query, array(33));
var_dump($result);

try{
    $query = "INSERT INTO test SET id = ?, reg_date = ?";
    $result = $DB->query($query, array(33, date("Y-m-d H:i:s")));
}catch(\MySQLiLib\Exception $e){
    //print error message "Duplicate entry '33' for key 'PRIMARY'"
    var_dump($e->getMessage());
}

$query = "INSERT INTO test SET id = ?, reg_date = ?";
$DB->bind_param('i');
$result = $DB->query($query, array(33, date("Y-m-d H:i:s")));
var_dump($result);

$query = "DELETE FROM test SET id = ?";
$DB->bind_param('i');
$result = $DB->query($query, array(33));
var_dump($result);