Я работаю с чат-ботом с открытым исходным кодом на основе PHP и пытаюсь сохранить сообщение, введенное конечным пользователем, в бот, который вызвал функцию «отката».так, чтобы я мог видеть, какие вещи люди спрашивают у бота, о которых я не могу строить логику / ответы.Однако моя проблема заключается в том, что MySQL вставка не работает.если я беру свой фактический запрос и передаю его в phpmyadmin, запрос работает, но на странице php он не работает, поэтому пытаюсь выяснить, что он может не работать.
Вот мой полный код
<?php
require_once('../vendor/autoload.php');
use BotMan\BotMan\BotMan;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Drivers\DriverManager;
use BotMan\BotMan\Middleware\ApiAi;
DriverManager::loadDriver(\BotMan\Drivers\Web\WebDriver::class);
$config = [
'web' => [
'matchingData' => [
'driver' => 'web',
],
]
];
$botman = BotManFactory::create($config);
$dialogflow = ApiAi::create('123abc')->listenForAction();
// Apply global "received" middleware
$botman->middleware->received($dialogflow);
//lets open connection to the mysql database
$chatdbconn = mysqli_connect("localhost","root","root","chatdb");
$chatdatetime = date('Y-m-d H:i:s');
/////////////////////////////////////
// DIALOG FLOW
/////////////////////////////////////
$botman->hears('hello|customerservice_contact|brand_feeling', function (BotMan $bot) {
// The incoming message matched the "my_api_action" on Dialogflow
// Retrieve Dialogflow information:
$extras = $bot->getMessage()->getExtras();
$apiReply = $extras['apiReply'];
$apiAction = $extras['apiAction'];
$apiIntent = $extras['apiIntent'];
$bot->typesAndWaits(2);
$bot->reply($apiReply);
})->middleware($dialogflow);
$botman->fallback(function($bot) {
global $chatdbconn;
$phrase = $bot->getMessage();
$unknownphrase = mysqli_real_escape_string($chatdbconn, $phrase->getText());
//$created_on = date('Y-m-d H:i:s');
mysqli_query($chatdbconn, "INSERT into chatbot_unknown_phrases(the_phrase) VALUES('$unknownphrase')");
$bot->typesAndWaits(2);
$bot->reply('Sorry, I did not understand the command.');
});
// Start listening
$botman->listen();
?>