Php 在SQL表中存储对变量的引用

Php 在SQL表中存储对变量的引用,php,sql,Php,Sql,如何在SQL表中存储对变量的引用?我有以下代码: $id = 10; $variable_value = 'real value'; $connect_db=mysqli_connect('localhost', 'this', 'that', 'a_table'); $result = $connect_db->query("SELECT * FROM the_table where id = '$id'"); $row = $result->fetch_assoc(); $the

如何在SQL表中存储对变量的引用?我有以下代码:

$id = 10;
$variable_value = 'real value';
$connect_db=mysqli_connect('localhost', 'this', 'that', 'a_table');
$result = $connect_db->query("SELECT * FROM the_table where id = '$id'");
$row = $result->fetch_assoc();
$the_function = $row['trigger']; // this row has a value '$variable_value' (w.o quotes)
echo '$the_function:'.$the_function.'<br>'; // echoes '$variable_value'
$id=10;
$variable_value='实际值';
$connect_db=mysqli_connect('localhost','this','that','a_table');
$result=$connect_db->query(“从_表中选择*,其中id='$id');
$row=$result->fetch_assoc();
$theu函数=$row['trigger'];//此行有一个值“$variable\u value”(不带引号)
回显“$the_function:”.$the_function.“
”;//回显“$variable_value”
是否可以让它回显“真实值”?

试试:

 $the_function = $row['trigger']; // this row has a value '$variable_value' (w.o quotes)
 $the_function = ltrim($the_function,'$');
 echo '$the_function:'.${$the_function}.'<br>'; 
$theu函数=$row['trigger'];//此行有一个值“$variable\u value”(不带引号)
$the_function=ltrim($the_function,“$”);
回显“$the_function:”。${$the_function}.
”;
这叫做变量名


要使其工作,必须删除
$
。因此,我将它从
$函数
中删除,并使用
${$}
将其作为其值的变量引用。

您可以使用变量来双重评估数据库值中的值:

$the_function = "variable_value";

echo $$the_function;
输出

real value
请注意,您不需要在数据库值前面加上
$
,这只会使问题复杂化

另外,你称它为“函数”这一事实让我觉得你想用它来调用一个名为变量的函数。。。你也可以这样做

function variable_value() {
   echo "real value"; 
}
$the_function();
这两种方法都在起作用:


是否要将$variable\u值保存到数据库中?否,我要将对$variable\u值的引用保存到数据库中