PHP code example of jpi / database
1. Go to this page and download the library: Download jpi/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/ */
jpi / database example snippets
$rows = $connection->selectAll("SELECT * FROM users;");
/**
$rows = [
[
"id" => 1,
"first_name" => "Jahidul",
"last_name" => "Islam",
"email" => "[email protected] ",
"password" => "password123",
...
],
[
"id" => 2,
"first_name" => "Test",
"last_name" => "Example",
"email" => "[email protected] ",
"password" => "password123",
...
],
...
];
*/
$row = $connection->selectFirst("SELECT * FROM users LIMIT 1;");
/**
$row = [
"id" => 1,
"first_name" => "Jahidul",
"last_name" => "Islam",
"email" => "[email protected] ",
"password" => "password",
...
];
*/
// INSERT
$numberOfRowsAffected = $connection->exec(
"INSERT INTO users (first_name, last_name, email, password) VALUES (:first_name, :last_name, :email, :password);",
[
"first_name" => "Jahidul",
"last_name" => "Islam",
"email" => "[email protected] ",
"password" => "password",
]
);
// UPDATE
$numberOfRowsAffected = $connection->exec(
"UPDATE users SET first_name = :first_name WHERE id = :id;",
[
"id" => 1,
"first_name" => "Pabel",
]
);
// DELETE
$numberOfRowsAffected = $connection->exec("DELETE FROM users WHERE id = :id;", ["id" => 1]);