2016-11-08 10 views
1

我嘗試將一個正在運行的SQL查詢放入我的Cronjob的PHP文件中。但是,我只收到空白的500內部服務器錯誤通知。PHP中的SQL查詢和輸出不起作用 - 500內部服務器錯誤

SQL查詢在PHPmyAdmin中正常工作。

下面的代碼:

<?php 
    $con=mysqli_connect("HOST","DBUSER","DBPW","DBNAME"); 
    // Check connection 
    if (mysqli_connect_errno()) 
     { 
     echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
     } 

    $result = mysqli_query($con,"SELECT oc_order_product.order_id AS bestellnr, oc_order_product.quantity, oc_order_product.model, oc_order_product.name, oc_order.shipping_company, oc_order.shipping_firstname, oc_order.shipping_lastname, oc_order.shipping_city 
FROM oc_order_product, oc_order 
WHERE oc_order.order_id = oc_order_product.order_id 
AND oc_order.order_status_id = 1 
ORDER BY bestellnr, model"); 

    while($row = mysqli_fetch_array($result)) 
     { 
     echo $row['oc_order_product.order_id'] . "; " . $row['oc_order_product.quantity'] "; " . $row['oc_order_product.model'] "; " . $row['oc_order_product.name'] "; " . $row['oc_order.shipping_company'] "; " . $row['oc_order.shipping_firstname'] "; " . $row['oc_order.shipping_lastname'] "; " . $row['oc_order.shipping_city']; //these are the fields that you have stored in your database table 
     echo "<br />"; 
     } 

    mysqli_close($con); 
    ?> 

error_log裏是空的。我的代碼有問題嗎? 錯誤消息,我通過郵件收到IST:

狀態:500內部服務器錯誤 X供電-者:PHP/5.6.19 內容類型:text/html的; charset = UTF-8

任何想法? 感謝名單

回答

0

我可以指出,這是不正確的:

$row['oc_order_product.order_id'] 

該行有使用這個名稱的列。事實上,您已明確給出名稱爲bestellnr的列。所以,你可以嘗試:

$row['bestellnr'] 

雖然我不能保證這是唯一的問題。

+0

神奇。可能是這樣的。我發現了其他一些小錯誤,現在它工作正常。 – 27eleven

0

這是最終代碼:

<?php 
$pdo = new PDO('mysql:host=DBHOST;dbname=DBNAME', 'DBUSER', 'DBPW'); 

$sql = "SELECT oc_order_product.order_id AS bestellnr, oc_order_product.quantity, oc_order_product.model, oc_order_product.name, oc_order.shipping_company, oc_order.shipping_firstname, oc_order.shipping_lastname, oc_order.shipping_city 
FROM oc_order_product, oc_order 
WHERE oc_order.order_id = oc_order_product.order_id 
AND oc_order.order_status_id = 1 
ORDER BY bestellnr, model"; 

foreach ($pdo->query($sql) as $row) { 
    echo $row['bestellnr']."; ".$row['quantity']."; ".$row['model']."; ".$row['name']."; ".$row['shipping_company']."; ".$row['shipping_firstname']."; ".$row['shipping_lastname']."; ".$row['shipping_city']."<br />"; 
} 

?>