php - 像返回类型函数一样动态查询
问题描述
像返回类型函数一样动态查询我们可以在我的编程领域使用像动态返回类型函数这样的动态函数吗?
<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);
推荐阅读
- docker - 其他电脑无法访问k8s仪表盘
- python - Pandas 和 FastParquet 读取单个分区
- javascript - 如何为谷歌表单的预填链接生成二维码
- google-bigquery - firebase转换的event_params值是什么意思?
- html - 如何在网络上的移动和桌面上设置徽标样式?
- facebook - Facebook:当 Webhook 仅在 Pushlish 模式下运行时,如何证明 publish_pages 正确?
- google-apps-script - 有条件地运行 Google 表格自定义函数
- html - Shopify如何让产品图片全屏显示?
- python - 使用 BeautifulSoup 从 HTML 表中抓取一列
- r - 在R中没有if语句的情况下从向量中删除