我试图将变量绑定到我的PHP预处理语句。但是,我试图将其应用于数据库名称,而不是值。这就是我所拥有的,有效:
$foo = 'foo';
$con = mysqli_connect(connection_values);
$query = "INSERT INTO example (field) VALUES ?;";
$stmt = mysqli_stmt_init($con);
$stmt->prepare($query);
$stmt->bind_param('s', $foo);
$stmt->execute();
我尝试做的事情与此类似:
$foo = 'foo';
$bar = 'bar';
$con = mysqli_connect(connection_values);
$query = "INSERT INTO example_? (field) VALUES ?;";
$stmt = mysqli_stmt_init($con);
$stmt->prepare($query);
$stmt->bind_param('ss', $bar, $foo);
$stmt->execute();
这会将foo
插入表格example_bar
。但是,使用
mysqli_stmt :: bind_param():无效的对象或资源mysqli_stmt
mysqli_stmt :: execute():无效的对象或资源mysqli_stmt
这可能吗?