当我在 phpmyadmin 中运行以下查询时,我得到了 18 个结果——所有这些结果都是正确的,并且是我正在寻找的。但是,当我将查询复制并粘贴到一个 php 文件并运行该页面时,我得到了 17 个结果。
SELECT
ta.jobTaskID,
jt.customTaskTitle, jt.taskID, jt.status,
d.dealershipName,
j.jobNumber, j.jobID, j.title, j.jobSpec,
wt.taskName,
po.dueToProduction
FROM taskassignments ta
INNER JOIN jobTasks jt ON ta.jobTaskID = jt.jobTaskID
INNER JOIN jobs j ON jt.jobID = j.jobID
INNER JOIN dealerships d ON j.dealershipID = d.dealershipID
LEFT JOIN workflowtasks wt ON jt.taskID = wt.taskID
LEFT JOIN purchaseorders po ON j.jobID = po.jobID
WHERE ta.userID = 1 AND jt.status != 'Completed';
编辑:这是我的 phpmyadmin 结果的快照 ,这是我的 var_dump 的快照。
这是我的 PHP 代码(我使用我创建的数据库类)
$myTasks = $connection->runQuery("
SELECT
ta.jobTaskID,
jt.customTaskTitle, jt.taskID, jt.status,
d.dealershipName,
j.jobNumber, j.jobID, j.title, j.jobSpec,
wt.taskName,
po.dueToProduction
FROM taskassignments ta
INNER JOIN jobTasks jt ON ta.jobTaskID = jt.jobTaskID
INNER JOIN jobs j ON jt.jobID = j.jobID
INNER JOIN dealerships d ON j.dealershipID = d.dealershipID
LEFT JOIN workflowtasks wt ON jt.taskID = wt.taskID
LEFT JOIN purchaseorders po ON j.jobID = po.jobID
WHERE ta.userID = " . $userID . " AND jt.status != 'Completed'");
最后,这是连接类用来运行查询的代码:
// runs the user defined query
public function runQuery($runMe)
{
$outArray = array();
if ($this->checkConnection()) // if the connection is a resource
{
$returned = mysql_query($runMe, $this->dbConnection);
if ($returned === false) // if there was an error during sql execution
{
echo "SQL Query error: " . mysql_error();
}
if ($returned === true) // if a update, insert, delete, etc... command was run
return true;
if (is_resource($returned))
{
$outArray = array(); // returned array with query results
for ($i = 0; $i < mysql_num_rows($returned); $i++)
{
$outArray[] = mysql_fetch_assoc($returned);
}
}
if (count($outArray) < 1)
return null;
else
return $outArray;
}
else
echo "Your Database Connection Was Unable To Be Authenticated.";
}