简体   繁体   English

传递db_query作为参数

[英]Passing a db_query as a parameter

I am trying to pass a db_query as a parameter in a function, but I am not getting what I want. 我试图将db_query作为函数中的参数传递,但是我没有得到想要的东西。
For example 例如

function some_function(){
    $query = "SELECT text FROM my_table";
    $result = db_query( $query );

    $text = other_function( $result );

    echo $text;
}

function other_function( &$result ){
     $array = db_fetch_array( $result );
     return $array['text'];
}

I have verified that the query works and that this works if I don't run it through another function. 我已验证该查询是否有效,并且如果不通过其他功能运行该查询,该查询也将有效。 Any ideas of what I am doing wrong? 关于我在做什么错的任何想法? Any ideas of a better way to do this? 有更好的方法可以做到这一点吗? I would still like to be able to use a separate function to fetch the arrays from my db_query if possible. 我仍然希望能够使用单独的函数从db_query中获取数组(如果可能)。

remove the &. 去除 &。 It seems unnecessary here. 这里似乎没有必要。 Also, I would use objects for this sort of job, this way you can simply use $this->result or its similarities. 另外,我将对象用于这种工作,这样您就可以简单地使用$this->result或其相似之处。

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

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