2014-12-06 140 views
1

我知道,我知道,听起来很奇怪。在heroku上的Flask应用程序中运行PHP脚本

我在heroku上有一个烧瓶应用程序,它运行得很好。我必须有一个运行PHP脚本的页面,与我的烧瓶后端几乎没有任何关系。它连接到外部数据库并在页面上呈现几行。例如,

<?php 
    mysql_connect($hostname, $username, $password) or DIE ("connection failed"); 
    mysql_select_db($dbname); 
    $id = REQUEST["id"]; 
    $query = "select * from table1" 
    $result = mysql_query($query) or die(mysql_error()); 
    $row = mysql_fetch_array($result); 
?> 
// leaving out for brevity 
<div class="container"> 
    <?php 
    echo "$row['name']<br/>" 
    ?> 
</div> 

但是,如果可能,我宁愿不做一个全新的应用程序来运行一到三个PHP脚本。所有重要的是PHP页面中的脚本运行。 db是一个外部mysql数据库

是否有可能沿着一个烧瓶应用程序运行它?如果是这样,怎么样?

+1

顺便说一句,你真的** **不应该使用'mysql_ *'方法,因为它们是不安全的。使用['MySQLi'](http://php.net/manual/en/book.mysqli.php)或['PDO'](http://php.net/manual/en/ref.pdo-mysql。 PHP)对象。 – MattDMo 2014-12-06 20:43:04

回答

2

首先,您需要确保您的Heroku应用程序在安装PHP的情况下运行;可能它不会。

您可能会使用PHP和Python附带的custom build pack来获取此信息。

一旦你有了PHP,你就可以运行从Python调用PHP解释器的脚本。

php_output = subprocess.check_output(["php", "script.php"])

相关问题