1. Go to this page and download the library: Download knobik/sql-agent 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/ */
knobik / sql-agent example snippets
use Knobik\SqlAgent\Facades\SqlAgent;
$response = SqlAgent::run('Who are our top 5 customers by spending?');
$response->answer; // "Here are the top 5 customers..."
$response->sql; // "SELECT c.name, SUM(o.total_amount) / 100 AS total_spent..."
$response->results; // [['name' => 'Lowell Boyer', 'total_spent' => 3930.15], ...]
use Knobik\SqlAgent\Facades\SqlAgent;
use Knobik\SqlAgent\Data\AgentResponse;
public function test_it_handles_sql_agent_response(): void
{
SqlAgent::shouldReceive('run')
->with('How many users?')
->andReturn(new AgentResponse(
answer: 'There are 100 users.',
sql: 'SELECT COUNT(*) FROM users',
results: [['count' => 100]],
));
$response = $this->post('/api/query', ['question' => 'How many users?']);
$response->assertJson(['answer' => 'There are 100 users.']);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.