以下是我的环境的广泛概述
数据库:
所以代码的作用是:
但是出于某种原因,每次cron运行这段代码来检查赏金是否完成时,即使它仍然不完整,它也会将其标记为非活动状态。
以下是我的代码,它应检查sysaid上的已关闭状态,然后更新表。但是它只是在没有关闭票证的情况下改变状态。
<?php
$servername = "*.*.*.*.";
$username = "*";
$password = "*";
$dbname = "Gamification";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection Failed : " . $conn->connect_error);
}
$sql = "SELECT * FROM performance_bounties";
$result = $conn->query($sql);
while ($row = $result->fetch_assoc()) {
$ticket_number = $row['ticket_number'];
$bounty_value = $row['bounty_value'];
$bounty_completed = $row['completed'];
$bounty_completed_by = $row['completed_by'];
$bounty_enabled = $row['enabled'];
check_sysaid($ticket_number, $bounty_value, $bounty_completed, $bounty_completed_by, $bounty_enabled);
}
function check_sysaid($ticket_number, $bounty_value, $bounty_completed, $bounty_completed_by, $bounty_enabled) {
$servername = "*.*.*.*";
$username = "*";
$password = "*";
$dbname = "Gamification";
$conn2 = new mysqli($servername, $username, $password, $dbname);
if ($conn2->connect_error) {
die("Connection Failed : " . $conn2->connect_error);
}
putenv("TDSVER=80");
putenv("FREETDSCONF=/etc/freetds/freetds.conf");
putenv("ODBCSYSINI=/etc/odbcinst.ini");
putenv("ODBCINI=/etc/odbc.ini");
$myServer = "TS";
$username = "*";
$password = "*";
$database = "SYSAID";
//connection to the database
$dbhandle = mssql_connect($myServer, $username, $password)
or die("Couldn't connect to SQL Server on $myServer");
//select a database to work with
$selected = mssql_select_db($database, $dbhandle)
or die("Couldn't open database $myDB");
$sysaidcheckquery = "
SELECT id, substring(responsibility,11,11) as responsibility, status from service_req where id = '" . $ticket_number . "'";
$sysaidcheckresult = mssql_query($sysaidcheckquery);
$numRows = mssql_num_rows($sysaidcheckresult);
while ($sysaidrow = mssql_fetch_array($sysaidcheckresult)) {
echo $ticketstatus;
$ticketid = $sysaidrow['id'];
$ticketresponsibility = $sysaidrow['responsibility'];
$ticketstatus = $sysaidrow['status'];
if ($ticketstatus = "27") {
$bountysqlupdate = "UPDATE performance_bounties SET enabled = '0', completed = '1', completed_by = '" . $ticketresponsibility . "' WHERE ticket_number = " . $ticket_number;
$performanceupdate = "UPDATE performance_q3_2018 SET bounties = '" . $bounty_value . "' where user_name = '" . $ticketresponsibility . "'";
if ($conn2->query($bountysqlupdate) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn2->error;
}
if ($conn2->query($performanceupdate) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn2->error;
}
}
}
}
?>
答案 0 :(得分:4)
您正在分配(=
)而不是比较(==
)。
$ticketstatus = "27"
将始终评估为true。它应该是
if ($ticketstatus == "27") {