gpt4 book ai didi

php - 从 php 执行 SQL 选择时出错

转载 作者:行者123 更新时间:2023-11-29 16:22:32 24 4
gpt4 key购买 nike

当我从 phpmyadmin 在 $stmt 中执行 SQL 时,它工作正常并且得到了所需的结果。然而,从 PHP 中,它进入异常代码块。另外,mysqli_errormysqli_errno 为空。

这是我的 PHP 代码:

<?php

header('Content-Type: application/json');

$fp = file_put_contents('1.log', "1 - Started \r\n");

function processMessage($update) {

$fp = file_put_contents('1.log', "Inside processMessage \r\n", FILE_APPEND);

if($update["result"]["action"] == ""){

$fp = file_put_contents('1.log', $update["result"]["parameters"]["plannumber"]."\r\n", FILE_APPEND );

$planNo = $update["result"]["parameters"]["plannumber"];

$stmt = "select count(*) AS reccount from plandetails where plannumber = '$planNo'";

$fp = file_put_contents('1.log', "Statement=".$stmt."\r\n", FILE_APPEND);

$result = mysqli_query($connection,$stmt);

$fp = file_put_contents('1.log', "Result=".$result."\r\n", FILE_APPEND);

if (!$result) {

$errno = mysqli_errno($connection);

$fp = file_put_contents('1.log',"Error in Select Query: ". $errno . "\r\n", FILE_APPEND);
exit;

}

$data = mysqli_fetch_assoc($result);

$count = $data['reccount'];

$fp = file_put_contents('1.log', "Count=".$count."\r\n", FILE_APPEND);

If ($count > 0) {
$speech = 'What is your Member ID';
}
else {
$speech = 'Plan Number $planNo not found';
}

$fp = file_put_contents('1.log', "Speech=".$speech, FILE_APPEND);

sendMessage(array(
"source" => $update["result"]["source"],
//"speech" => $update["result"]["parameters"]["plannumber"],
"speech" => $speech,
"displayText" => "........Text Here...........",
"contextOut" => array()
));
}

}

function sendMessage($parameters) {
$req_dump = print_r($parameters, true);
$fp = file_put_contents( 'Response.log', $req_dump);
header('Content-Type: application/json');
echo json_encode($parameters);
}

//open DB connection
$host = "localhost";
$username = "XXXX";
$password = "XXXX";
$database = "XXXX";

$connection = mysqli_connect ($host, $username, $password, $database);

if (mysqli_connect_errno()) {
$con_errno = mysqli_connect_error();
file_put_contents('1.log',"Error in DB Connection: " . $con_errno. "\r\n", FILE_APPEND);
exit();
}

$update_response = file_get_contents("php://input");
$fp = file_put_contents('input.log', $update_response);

$update = json_decode($update_response, true);

if (isset($update["result"]["action"])) {
$fp = file_put_contents('1.log', "Inside isset:".$update."\r\n");
processMessage($update);
}

mysqli_close($connection);

?>

最佳答案

在函数processMessage中,$connection的值是多少?它不是全局变量,并且您没有将其作为参数传递给函数

关于php - 从 php 执行 SQL 选择时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54448862/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com