By using php agi getting an error not found can anyone help me to resolve the issue

Here is my call.php file (Not working with the script). by getting value directly from database

• How to get extension number from database dynamically (without storing the value manually in extension.conf file). write the script for extension.conf file.

• How to add destination number from database dynamically (without storing the value manually in extension.conf file). write the script for extension.conf file.

#!/usr/bin/php -q
<?php
$dbusername = "asterisk";
$dbname     = "myphonesystems";
$dbpass     = "Asterisk@123";
$dbhost     = "127.0.0.1";

// Connect to the database
$conn = mysqli_connect("$dbhost", "$dbusername", "$dbpass", "$dbname");

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

// Import the PHPAGI library
require_once('/var/lib/asterisk/agi-bin/phpagi.php');

// Create an instance of the AGI class
$agi      = new AGI();
$userName = $agi->request['agi_arg_1'];
$ext      = $agi->request['agi_arg_2'];
$user_id  = $agi->request['agi_arg_3'];
$sip_file = "/etc/asterisk/sip.conf";
$file     = fopen($sip_file, 'r');
// $user_id = null;

// Read the file line by line
while (($line = fgets($file)) !== false) {
Check if the line starts with the user's name in square brackets
    if (preg_match('/^[' . preg_quote($userName) . ']/', $line)) {
        // If it does, set the $user_data variable
        $user_data = $line;
        // Extract the user ID from the SIP configuration
        if (preg_match('/^user_id=(d+)/', $line, $matches)) {
            $user_id = $matches[1];
        }
    }
}

fclose($file);

if ($user_id) {
    if ($ext == "get_number") {
        $extension_query = "SELECT extension_name FROM extensionmps WHERE user_id=?";
        $stmt            = mysqli_prepare($conn, $extension_query);
        mysqli_stmt_bind_param($stmt, "i", $user_id);
        mysqli_stmt_execute($stmt);
        $result = mysqli_stmt_get_result($stmt);
        if ($row = mysqli_fetch_assoc($result)) {
            $cuser = $row['extension_name'];
            $agi->verbose($cuser);
            $agi->set_variable("CALLERID(num)", $userName);
            $agi->set_variable("CALLERID(name)", $userName);
            $agi->set_variable('call_number', $cuser);
        }
        mysqli_stmt_close($stmt);
    }
} else {
    $agi->verbose("User with username $userName is not registered");
}

Dial the extension number
$dial = $agi->exec("Dial", "SIP/${call_number}");

// Hang up the call
$agi->exec("Hangup", "");
?>

extension.conf file:::

[phones]
exten => _X.,1,AGI(call.php?userName=${CALLERID(num)})
exten => _X.,2,Dial(${call_number})