1. Go to this page and download the library: Download jake142/querai 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/ */
jake142 / querai example snippets
'hints' => [
'enabled' => true,
'text' => <<<'HINTS'
- A customer is a row in users; find by users.email
- An order belongs to a customer: orders.user_id = users.id
- "Revenue" means SUM(orders.total) where orders.status = 'completed'
- Do NOT use the audit_log table unless the question is about audit events
HINTS,
],
use Querai\Facades\Querai;
$result = Querai::ask('How many active users do we have?');
echo $result->answer; // Human-readable reply
echo $result->sql; // SQL that was executed
echo $result->rowCount; // Number of rows returned
echo $result->attempts; // Query attempts (retries on error)
$id = 'user-session-abc';
Querai::ask('How many orders last month?', $id);
Querai::ask('Break that down by country', $id);
$result = Querai::ask('List all products with stock below 10');
if ($result->hasMore) {
$next = Querai::continue($result->responseId);
echo $next->answer; // next batch, human-readable
}
use Querai\Facades\Querai;
$result = Querai::ask($request->input('question'));
return response()->json($result->toArray());