1. Go to this page and download the library: Download jameslevi/hadron 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/ */
jameslevi / hadron example snippets
use Graphite\Component\Hadron\Hadron;
// Import hadron into your project.
use Graphite\Component\Hadron\Hadron;
// Create a new Hadron instance.
$conn = new Hadron('database');
// Set your MySQL username and password.
$conn->setCredentials('username', 'password');
// Create a new query.
$query = $conn->query('SELECT * FROM users WHERE id = :id LIMIT :start, :offset');
// Set the value of the parameters.
$query->addParam('id', 1)
->addParam('start', 0)
->addParam('offset', 10);
// Get the results from the query.
$results = $query->get();
// Close connection from the database.
$conn->close();
$conn = new Hadron('database');
$conn = Hadron::database();
$conn->setCredentials('username', 'password');
$conn->setServerName('localhost');
$conn->setPort(3303);
$conn->setCharset('utf8mb4');
$conn->connect();
$conn->isConnected();
$conn->close();
$query = $conn->query('SELECT first_name, last_name, gender FROM members')->get();
foreach($query->all() as $member)
{
echo $member->name;
}
var_dump($query->toArray());
echo $query->toJson();
$query = $conn->query('UPDATE members SET first_name = :first_name WHERE id = :id');
$query->addParam('first_name', 'James Levi')
->addParam('id', 1);
$query->exec();