PHP code example of dottwatson / fpdo
1. Go to this page and download the library: Download dottwatson/fpdo 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/ */
dottwatson / fpdo example snippets
return [
...
'connections' => [
...
'test_fpdo' => [
'driver' => 'fpdo',
'database' => \App\FpdoDatabases\TestFpdo\Database::class,
'options' => [
PDO::ATTR_CASE => PDO::CASE_LOWER //optional
]
],
],
...
];
namespace App\FpdoDatabases\TestFpdo;
use Fpdo\Definitions\Database as FpdoDatabaseDefinition;
class Database extends FpdoDatabaseDefinition{
public $name = 'testfpdo';
protected $collation = 'utf8mb4_unicode_ci';
protected $prefix = '';
protected $prefix_index = true;
protected $strict = true;
protected $options = [];
public function tables()
{
return [
\App\FpdoDatabases\TestFpdo\Tables\Products::class
];
}
}
namespace App\FpdoDatabases\TestFpdo\Tables;
use Fpdo\Definitions\Table;
use Illuminate\Database\Schema\Blueprint;
class Products extends Table {
protected $name = 'products';
public function define(Blueprint $table)
{
$table->increments('id');
$table->string('title');
$table->string('description')->nullable();
$table->decimal('price');
$table->decimal('discountPercentage');
$table->decimal('rating');
$table->integer('stock')->default(0);
$table->string('brand')->nullable();
$table->string('category');
}
protected function reader()
{
$file = storage_path('app/catalog/products.json');
$data = json_decode(file_get_contents($file), true);
return $data;
}
protected function writer(array $data = null)
{
$str = json_encode($data, JSON_PRETTY_PRINT);
$file = storage_path('app/catalog/products.json');
file_put_contents($file, $str);
}
}
namespace My\FpdoFunctionsExtensions;
use Fpdo\Definitions\QueryFunctionsEvaluator;
use Vimeo\MysqlEngine\Processor\ProcessorException;
class Greetings extends QueryFunctionsEvaluator {
public static function handle(string $functionName, array $params)
{
if ($functionName == 'GREETINGS') {
if (count($params) < 1) {
return new ProcessorException("Function " . $functionName . " expects 1 parameter");
}
return 'Hello ' . $params[0];
} else {
return new ProcessorException("Function " . $functionName . " not implemented yet");
}
}
}
return [
...
'extensions' => [
...
My\FpdoFunctionsExtensions\Greetings::class,
...
]
]
sql
SELECT * FROM table WHERE PHP_EVAL('return 10/5;') = 2
bash
php artisan vendor:publish --provider="Fpdo\FpdoServiceProvider" --tag=fpdo-config