/*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变量中, –