PhpStorm live templates: is it possible to have any number of variables

一笑奈何 提交于 2020-01-03 04:47:10

问题


I want to create a template for an insert SQL block of code in PHP.

Templates are great to fill in the same value where it is repeated numerous times.

Is it possible to have the live template keep repeating certain blocks of code until I exit the template generation?

For example I want the template to be able to cater for any number of variable in an Insert statement.

It would be great if I can just enter variables until I'm done and the template repeats certain parts until I'm done.

Please look at the following template:

$insert_sql = "INSERT INTO $TABLE$ (`$VAL$`,`$VAL1$`,`$VAL2$`,`$VAL3$`) VALUES (:$VAL$,:$VAL1$,:$VAL2$,:$VAL3$)";
$newq = $dbh->prepare($insert_sql);
$newq->bindParam(":$VAL$", $$$VAL$);
$newq->bindParam(":$VAL1$", $$$VAL1$);
$newq->bindParam(":$VAL2$", $$$VAL2$);
$newq->bindParam(":$VAL3$", $$$VAL3$);
try {
    $newq->execute();
} catch (PDOException $e) {
    die($insert_sql . "<br/>An SQL error occurred: " . $e->getMessage());
}
$lastid = $dbh->lastInsertId();

来源:https://stackoverflow.com/questions/38883122/phpstorm-live-templates-is-it-possible-to-have-any-number-of-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!