SQL Insert:如何使列变量?

时间:2022-04-17 22:26:36

I want to make a file, which inserts one or more values to one or more columns. How can I make the columns variable? Can I use a string for all columns and another for all values, separated with kommas?

我想创建一个文件,它将一个或多个值插入一个或多个列。如何使列变量?我可以为所有列使用字符串,为所有值使用另一个字符串,用kommas分隔吗?

1 个解决方案

#1


1  

In PHP, you can use variables in your sql query:

在PHP中,您可以在SQL查询中使用变量:

$table = 'mytable';

$col1 = 'mycolumn1';
$col2 = 'mycolumn2';

$val1 = 'myval1';
$val2 = 'myval2';

$q = "INSERT INTO $table ($col1, $col2) VALUES ($val1, $val2)";

#1


1  

In PHP, you can use variables in your sql query:

在PHP中,您可以在SQL查询中使用变量:

$table = 'mytable';

$col1 = 'mycolumn1';
$col2 = 'mycolumn2';

$val1 = 'myval1';
$val2 = 'myval2';

$q = "INSERT INTO $table ($col1, $col2) VALUES ($val1, $val2)";