我有我已經寫了下面的PHP函數。這是創建一個新的數據庫表,併爲它和另一個表插入一些值。PHP功能似乎只是半途而廢
function createTable($tablename, $mins){
$con=mysqli_connect("localhost","****","****","*****");
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$tableCreate = "CREATE TABLE rates_{$tablename} (
Weight int(11),
CBMMin double,
CBMMax double,
Min double
)";
$queryResult = mysqli_query($con, $tableCreate);
if ($queryResult === TRUE) {
print "<br /><br />Table Created";
} else {
print "<br /><br />No TABLE created. Check " . mysqli_error($con);
}
//Echo/print stop working here but below query does fire
$queryResult = mysqli_query($con, "INSERT INTO Custom_Rates (TableName) VALUES ('rates_{$tablename}');");
//everything below here does not
$rows = array(
array('weight' => 1000, 'cbm_min' => 0.1, 'cbm_max' => 2.3),
array('weight' => 1500, 'cbm_min' => 2.31, 'cbm_max' => 3.5),
array('weight' => 2000, 'cbm_min' => 3.51, 'cbm_max' => 4.6),
array('weight' => 2500, 'cbm_min' => 4.61, 'cbm_max' => 5.75),
array('weight' => 3000, 'cbm_min' => 5.75, 'cbm_max' => 6.9),
);
foreach ($rows as $row) {
$queryResult = mysqli_query($con, "INSERT INTO 'rates_".$tablename."' (Weight, CBMMin, CBMMax) VALUES (".$row['weight'].",".$row['cbm_min'].",".$row['cbm_max'].");");
if ($queryResult === TRUE) {
print "<br /><br />Row Created";
} else {
print "<br /><br />No Row created. Check " . mysqli_error($con);
}
}
這似乎是每個迴路簡單,如果因爲沒有東西打印語句被解僱不被解僱的無論是真還是假。 我又增加了額外的打印語句來調試什麼是真正進行最後的,似乎
$queryResult = mysqli_query($con, "INSERT INTO Custom_Rates (TableName)
VALUES ('rates_{$tablename}');");
線沒有什麼事情發生後,(我知道,這個查詢工作,因爲我可以看到在匯率表的日期) 。
任何想法什麼可以阻止從工作的foreach?
嘗試增加的error_reporting反正感謝(一期結束E_ALL^E_NOTICE);在你的代碼的頂部併發布結果 – Matheno
@Marijke沒有輸出 –
接受查詢並回顯整個查詢字符串,然後在mysql控制檯中嘗試 –