我刚刚开始将我的网站从mysql转换为mysqli,并将我的一个函数更改为mysqli。我上传了这个新功能,但现在没有从数据库中显示任何结果。那么这只是代码,还是整个网站在函数运行之前必须先在mysqli中?可能是因为我的数据库连接仍然是mysql? 我转换了这个
function viewOrdersAdmin(){
//This block grabs the orders
$order_list = "";
//Selecting all the orders in the table from that member
$sql = mysql_query("SELECT * FROM `transactions`");
while ($transactions = mysql_fetch_array($sql)) {
//creating variables from the information
$order_id = $transactions["order_id"];
$mem_id = $transactions["mem_id"];
$order_details = mysql_query("SELECT * FROM `transactionDetails` WHERE `order_id` = $order_id GROUP BY order_id");
$orderDetailsCount = mysql_num_rows($order_details);
while ($row = mysql_fetch_array($order_details)) {
//creating variables from the information
$order_product_id = $row["Product_ID"];
$member_details = mysql_query("SELECT * FROM `members` WHERE `mem_id` = $mem_id");
$memberDetailsCount = mysql_num_rows($member_details);
while ($row2 = mysql_fetch_array($member_details)) {
//creating variables from the information
$order_mem_fname = $row2["mem_first_name"];
$order_mem_lname = $row2["mem_last_name"];
$order_list .= "Order ID:$order_id - Customer Name: $order_mem_fname $order_mem_lname <a href='manage_order.php?orderid=$order_id'>View</a> • <a href='manage_orders.php?deleteid=$order_id'>Delete</a><br/>";
}
}
}
if (count($orderDetailsCount) == 0) {
$order_list = "You have no orders to display";
}
print_r($order_list);
}
到此
function viewOrdersAdmin(){
//This block grabs the orders
$order_list = "";
//Selecting all the orders in the table from that member
$sql = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM `transactions`");
while ($transactions = mysqli_fetch_array($sql)) {
//creating variables from the information
$order_id = $transactions["order_id"];
$mem_id = $transactions["mem_id"];
$order_details = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM `transactionDetails` WHERE `order_id` = $order_id GROUP BY order_id");
$orderDetailsCount = mysqli_num_rows($order_details);
while ($row = mysqli_fetch_array($order_details)) {
//creating variables from the information
$order_product_id = $row["Product_ID"];
$member_details = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM `members` WHERE `mem_id` = $mem_id");
$memberDetailsCount = mysqli_num_rows($member_details);
while ($row2 = mysqli_fetch_array($member_details)) {
//creating variables from the information
$order_mem_fname = $row2["mem_first_name"];
$order_mem_lname = $row2["mem_last_name"];
$order_list .= "Order ID:$order_id - Customer Name: $order_mem_fname $order_mem_lname <a href='manage_order.php?orderid=$order_id'>View</a> • <a href='manage_orders.php?deleteid=$order_id'>Delete</a><br/>";
}
}
}
if (count($orderDetailsCount) == 0) {
$order_list = "You have no orders to display";
}
print_r($order_list);
}
答案 0 :(得分:1)
如果要同时使用两个不同的库,则需要两个数据库连接:一个mysql连接和一个单独的mysqli连接。
但是,您可以同时使用两者而不会出现任何问题。它只会暂时使用更多资源,因为您有两个连接到通常有数据库的数据库。
顺便说一下,我不建议为数据库连接使用全局变量,你应该将它作为参数传递给你的函数,因为这样可以更容易地解决问题。
您还应该使用预准备语句来避免任何SQL注入问题。