我有三個文件conn.php
,在conn.php
我有我的數據庫連接func.php
和index.php
和index.php
而func.php
我已經計數數的函數我已經包括了連接文件列注意:未定義的變量:NUM
func.php
<?php
function countusers($connection, $column, $table)
{
$stmt = mysqli_prepare($connection, "
SELECT
COUNT($column)
FROM
$table");
if($stmt)
{
mysqli_stmt_bind_result($stmt, $num);
mysqli_execute($stmt);
mysqli_stmt_fetch($stmt);
mysqli_stmt_close($stmt);
}
return $num;
}
但它似乎沒有工作,我嘗試添加的功能連接文件和它的工作。
這裏是我的索引文件
的index.php
<?php
require_once "conn.php";
include "func.php";
echo countusers($conn, "id", "mods");
conn.php
<?php
$conn = mysqli_connect("localhost", "root", "", "test", 3306);
if(!$conn)
{
echo "An Error Occurred";
}
你有什麼錯誤嗎? – Raptor
也許你最好告訴我們'conn.php',因爲它看起來應該對我有用,除非連接出現問題 – RiggsFolly
不用注意'注意:未定義變量:num' –