gpt4 book ai didi

php - 像返回类型函数一样动态查询

转载 作者:行者123 更新时间:2023-12-01 07:04:03 24 4
gpt4 key购买 nike

像返回类型函数一样动态查询我们可以在我的编程领域使用像动态返回类型函数一样的动态函数吗

<html>
<head>
<title>Dynamic Querys</title>
</head>
<body>
<?php
public function fun($table){
$query="SELECT * FROM ".$table;
return $query;

}
echo fun("student");
?>
</body>
</html>

最佳答案

你可以这样做

function insert_data($table,$data){
$sql ="INSERT INTO ".$table;
$sql .=" (".implode(",",array_keys($data)).") VALUES";
$sql .=" ('".implode("','", array_values($data))."')";
$query=$conn->query($sql);
if ($query) {
return true;
}
else{
return false;
}
$query->close();
}

调用上层函数将数据插入表中。希望这能解决您的问题

$data=array('name' => "Yasir", 'age' => 25, 'education' => "Master");
$fet=insert_data("student",$data);

关于php - 像返回类型函数一样动态查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58668729/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com