[英]How to execute a PHP function which is stored in MySQL database
我正在尋找執行存儲在mysql表中的php函數。 例如
SQL query: SELECT * FROM `modules` WHERE uid=2 LIMIT 0, 30 ;
Rows: 1
uid moduleName source responsiveCode active
2 Testimonial this is a function <?php echo getUrl(); ?> 12 0
現在我想在每次檢索uid號2時執行getUrl()函數
您可以像這樣使用eval()
:
$result = mysqli_query($connection, "SELECT * FROM `modules` WHERE uid=2 LIMIT 0, 30");
$row = mysqli_fetch_assoc($result);
$function = $row['source'];
eval('?>' . $function . '<?php');
但是,我強烈建議您不要將功能存儲在數據庫中,因為這樣做會帶來巨大的安全風險。 相反,您可以這樣做:
uid | moduleName | source | responsiveCode | active
----------------------------------------------------------------
2 | Testimonial | this is a function | 12 | 0
$result = mysqli_query($connection, "SELECT * FROM `modules` WHERE uid=2 LIMIT 0, 30");
$row = mysqli_fetch_assoc($result);
echo $row['source'] . getUrl(); //will still print the same
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.