/*connection file*/
function connect(){
$server = "localhost";
$user = "xxxx";
$password = "xxxx";
$db = "xxxx";
$connetion = mysqli_connect($server,$user,$password,$db);
}
這是我的連接文件。我使用MVC連接到數據庫。mysqli_query()期望參數1爲mysqli,null給出
/*function declaration and insert query*/
function insert($table,$value){
$fld = "";
$val = "";
$i = 0;
foreach ($value as $k => $v) {
if($i == 0){
$fld .= $k;
$val .= "'" . $v ."'";
}
else{
$fld .= "," . $k;
$val .= ",'" .$v . "'";
}
$i++;
}
global $conn;
return mysqli_query($conn,"INSERT INTO $table($fld) VALUES($val)") or die(mysqli_error($conn));
}
當我嘗試向數據庫中插入數據時發出警告。
請幫我解決這個警告。
想看看你是如何擴展連接文件 –
include_once'./connection.php';我像這樣擴展了我的連接文件。 –
你需要使用return語句。並將其存儲在$ conn變量中, –