简体   繁体   English

我可以在 eval() 中执行 mysql_query 吗?

[英]Can I do a mysql_query in eval()?

The community builder I am using requires php blocks to be parsed through eval().我使用的社区构建器需要通过 eval() 解析 php 块。 Can I use the mysql_query in eval?我可以在 eval 中使用 mysql_query 吗? If not how can I call info from the database in this eval()?如果不是,我如何在这个 eval() 中调用数据库中的信息?

Here's my code so far:到目前为止,这是我的代码:

$iProId = $this->oProfileGen->_iProfileID;
$sCat = mysql_query("SELECT genres from Profiles WHERE ID = ". $iProId);
print_r($sCat);

This gives me:这给了我:
Resource id #167资源 ID #167

If that code gave you that result when eval'd then yes, you can use mysql_query in eval and the rest of your question boils down to how you would have to use that result set.如果该代码在 eval'd 时为您提供了该结果,那么是的,您可以在 eval 中使用 mysql_query 并且您问题的 rest 归结为您将如何使用该结果集。

In that case I would suggest something like:在这种情况下,我会建议类似:

$iProId = $this->oProfileGen->_iProfileID;
$sCat = mysql_query("SELECT genres from Profiles WHERE ID = ". $iProId);
while($row = mysql_fetch_assoc($sCat)) {
    print_r($row);
}

To loop over all rows in the resultset.遍历结果集中的所有行。 If you want to know more the PHP website has all the goods on how to use mysql_* functions.如果您想了解更多信息,PHP 网站上有关于如何使用 mysql_* 功能的所有商品。

Have a look at mysql_fetch_array (and the other mysql_fetch_* functions) for how to get your data from the resource.查看mysql_fetch_array (和其他mysql_fetch_*函数),了解如何从资源中获取数据。

Using a query in eval() sounds strange to me, but you code is working right.在 eval() 中使用查询对我来说听起来很奇怪,但是您的代码工作正常。 mysql_query returns a mysql resource. mysql_query返回 mysql 资源。 Then you need to you mysql_fetch_array , mysql_fetch_row , or mysql_fetch_assoc to read it like:然后你需要mysql_fetch_arraymysql_fetch_rowmysql_fetch_assoc来读取它:

$iProId = $this->oProfileGen->_iProfileID;
$result = mysql_query("SELECT genres from Profiles WHERE ID = ". $iProId);
$sCat = mysql_fetch_assoc($result);
print_r($sCat);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM