php - Using variable data to replace hard-coded table name in a query -
let's have prepared statement, in case, 1 selects photo information specific table in database:
$conn = dbconnect('query'); $bgimage = "select photo_fname photos_bn gallery_id = ? limit $curpage,".$totalpix; $stmt = $conn->prepare($bgimage); $stmt->bind_param('i', $gallery); $stmt->bind_result($pfname); $stmt->execute(); $stmt->store_result(); $stmt->fetch();
and since have several tables in database deal specific photo themes, 1 assume need separate queries each table. above code selects information table, photos_bn
, have other tables, we'll call them, photos_bq
, photos_ps
.
this may insanely obvious question, how go replacing table name variable passed page via query string or session variable table name in query not hard coded, part of prepared statement?
many thanks!
you have:
$bgimage = "select photo_fname ".$_get["querystringvar"]." gallery_id = ? limit $curpage,".$totalpix;
be warned leaves vulerable sql injection
Comments
Post a Comment