私は三つのファイルconn.php
、func.php
とconn.php
でindex.php
を持っている私は、データベースへの私の接続を持っているとfunc.php
に、私は数を数える機能をした一方でindex.php
に私は接続ファイルを含めました列注意:未定義の変数:NUM
<?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;
}
func.php
の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
いいえ、通知しないでくださいNotice:未定義の変数:num' –