1. Go to this page and download the library: Download jrdev/mysql 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/ */
jrdev / mysql example snippets
$db = new \jrdev\MySQL('host', 'user', 'pass', 'database');
$query = $db->query('SELECT ...');
$query = $db->select('table_name', 'field1, field2');
if ($query)
{
echo 'Num Rows: ', $query->num_rows, '<br>';
foreach ($query as $row)
{
echo $row['first_name'], '<br>';
}
}
else
{
echo $db->error();
}
// The $where (third param) accepts array, string or integer:
$query = $db->select('table_name', 'field1', ['name' => 'Pepe']); // With array.
$query = $db->select('table_name', 'field1', 'name = "Pepe"'); // With string.
$query = $db->select('table_name', 'field1', 1); // With integer. In this case, the resulting sql for the "WHERE" is "id = 1".