在PHP中调用多个函数

时间:2016-06-27 22:53:39

标签: php function

我有一个页面,其中包含调用数据库的所有函数。在我的显示页面中,我试图调用两个单独的函数。这不可能吗?以下是我的代码。

<?php
include 'includes/getData.php';
$memberBios = getActiveMemberBios();
$internBios = getActiveInternBios();
?>

<h3>Members</h3>
            <?php
                while($member = mysql_fetch_array($memberBios))
                {
                    $bioPic = $member['bioPic'];
                    $bioText = $member['bioText'];
                    $firstname = $member['firstname'];
                    $maidenname = $member['maidenname'];
                    $memberRole = $member['memberRole'];
                    $lastname = $member['lastname'];

                    echo
                    "<div class='row row__off-1 col-lg-12 wow fadeInUp' data-wow-delay='0.2s'>
                        <div class='col-lg-3 col-md-3 col-sm-12'>
                            <div class='text-center'>
                                <img src='".$bioPic."' alt='Biography Picture of Zion Dance Company Member '".$firstname.' '.$lastname." title='Biography Picture of Zion Dance Company Member '".$firstname.' '.$lastname. "height='305' width='270'/>
                            </div>
                        </div>
                        <div class='col-lg-9 col-md-9 col-sm-12 text-center-xs'>
                            <h5 class='font-secondary-3'>
                                <a href='#'>".$firstname.' '.$maidenname.' '.$lastname."</a>
                            </h5>
                            <p class='color-primary off'>".$memberRole."</p>

                            <p>".$bioText."</p>
                        </div>
                    </div>";
                }
            ?>
            <h3>Interns</h3>
            <?php
                while($intern = mysql_fetch_array($internBios))
                {
                    $bioPic = $intern['bioPic'];
                    $bioText = $intern['bioText'];
                    $firstname = $intern['firstname'];
                    $maidenname = $intern['maidenname'];
                    $memberRole = $intern['memberRole'];
                    $lastname = $intern['lastname'];

                    echo
                    "<div class='row row__off-1 col-lg-12 wow fadeInUp' data-wow-delay='0.2s'>
                        <div class='col-lg-3 col-md-3 col-sm-12'>
                            <div class='text-center'>
                                <img src='".$bioPic."' alt='Biography Picture of Zion Dance Company Member '".$firstname.' '.$lastname." title='Biography Picture of Zion Dance Company Member '".$firstname.' '.$lastname. "height='305' width='270'/>
                            </div>
                        </div>
                        <div class='col-lg-9 col-md-9 col-sm-12 text-center-xs'>
                            <h5 class='font-secondary-3'>
                                <a href='#'>".$firstname.' '.$maidenname.' '.$lastname."</a>
                            </h5>
                            <p class='color-primary off'>".$memberRole."</p>

                            <p>".$bioText."</p>
                        </div>
                    </div>";
                }
            ?>

每个方法都调用一个不同的存储过程。

每个方法都会正确地返回数据,直到它们被一个接一个地调用。

function getActiveMemberBios()
{
    mysql_connect(ZDANCE_CONNECTION, ZDANCE_USER, ZDANCE_PASS);
    if(mysql_ping())
    {
        mysql_select_db(ZDANCE_HOST);
        $result = mysql_query("CALL usp_GetMemberBios(1)") or die("Query fail: " . mysql_error());

        return $result;

        mysql_close();
    }
}

function getActiveInternBios()
{
    mysql_connect(ZDANCE_CONNECTION, ZDANCE_USER, ZDANCE_PASS);
    if(mysql_ping())
    {
        mysql_select_db(ZDANCE_HOST);
        $result = mysql_query("CALL usp_GetInternBios(1)") or die("Query fail: " . mysql_error());

        return $result;

        mysql_close();
    }
}

1 个答案:

答案 0 :(得分:3)

您的函数没有关闭它们的SQL连接,因为在返回操作之后放置了mysql_close函数。尝试替换这部分功能代码

return $result;

mysql_close();

用这个

mysql_close();

return $result;