0

I need help for this problem. I have a map of values:

$table = "tableName"
$columns = "col1", "col2", ... "coln"
$types = "col1type" .... "colntype"

Is it possible to use PDO Prepared statements to build a SQLITE query like this(example):

create table if not EXISTS 'tableName' ('col1' TEXT, 'col2' TEXT, ... , 'coln' TEXT);

of course not knowing in advance how many bind params I need to use, I would need a prepared statements template like this:

create table if not EXISTS ':tableName' (':col1Name' :col1Type, ':col2Name' :col2Type, ... , 'colnName' :colnType);

I was thinking of building the query by first concatenating the prepared statement:

$query = " create table if not EXISTS ':tableName' (";

for($i=0; i<count($columns); i++){
$query = $query . " ':col$iName' " . " :col$iType ";

if($i != count($columns) - 1){
$query = $query . ",";
}else {
$query = $query . ")";
}
}

then bind the params in another for cycle. I don't like this solution much, so I am asking if there is a better way of doing this.

Thank you for your help!

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345

0 Answers0