PHP:使用变量保存表名,并在查询中使用该变量 [英] PHP : Using a variable to hold a table name, and using that variable in queries
本文介绍了PHP:使用变量保存表名,并在查询中使用该变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在学习PHP,并且正在编写注册表. 在我的代码中的某个地方,我有这些语句
I am currently learning PHP, and I'm working on a Registration Form. Somewhere in my code I have these statements
$query = "SELECT `stud_no` FROM `tb_registered_users` WHERE `stud_no`='$studno'";
和
$query = "INSERT INTO `tb_registered_users`
VALUES ('".$studno."','".$firstname."','".$lastname."')";
但是我想声明这个变量,并在上面提到的查询中使用它
but instead I want to declare this variable and use it in the queries mentioned above
$mysql_tb = 'tb_registered_users';
那么正确的语法是什么?
So what is the correct syntax for this?
推荐答案
$query = "INSERT INTO `" . $mysql_tb . "`
VALUES ('".$studno."','".$firstname."','".$lastname."')";
这篇关于PHP:使用变量保存表名,并在查询中使用该变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文