bind_result( ) not getting all results

霸气de小男生 提交于 2020-01-05 04:15:26

问题


For some reason it executes the statement and then the bind_results returns all values but not the last value of $postContent.

<?php
            if (isset($_GET['postID']))
            {
                $postID = $_GET['postID'];
                $stmt = $mysqli->prepare("SELECT * FROM Posts WHERE postID = ?");
                $stmt->bind_param('i', $postID);
                $stmt->execute();
                $stmt->bind_result($postID, $postTitle, $postCat, $postUser, $postDateTime, $postContent);
                $stmt->fetch();
                echo $postContent;
                ?>
                <h1><?php echo $postTitle;?></h1>
            </div> <!-- End of box div -->
            <div class="blogroll"> <!-- Start of blogroll div -->
            <div class="top"></div> <!-- Start and end of top div -->

            <div class="post"> <!-- Start of post div -->
                <div class="post_date">Posted by <?php echo $postUser;?> on <?php echo $postDateTime ?> Category : <?php echo $postCat;?></div> <!-- Start and end of post_date div -->
                <div class="post_text"> <!-- Start of post_text div -->
                    <?php echo $postContent;?>
                </div> <!-- End of post_text div -->
                <?php
            }
        ?>

回答1:


This assumes your source table in the database is actually supplying a column for $postContent when you do SELECT *:

View the HTML source that is output by your PHP script, to see if the $postContent is actually appearing in the source but not onscreen. You have not escaped your database output for HTML (encoding < as &lt;, etc...), so it is possible that something in $postContent or an earlier variable is breaking your output. Instead of directly echoing out those variables, wrap each one in htmlspecialchars() when printing them inside HTML.

<?php echo htmlspecialchars($postTitle); ?>
<?php echo htmlspecialchars($postUser); ?>
<?php echo htmlspecialchars($postDateTime); ?>
<?php echo htmlspecialchars($postCat); ?>
<?php echo htmlspecialchars($postContent); ?>



回答2:


MySQLi is failing to allocate enough memory for the maximum size of a LONGTEXT object (~4Gb).

This is a known bug: https://bugs.php.net/bug.php?id=51386.

The workaround is to convert LONGTEXT columns to MEDIUMTEXT or something else smaller, or consider using an alternative database or interface class.



来源:https://stackoverflow.com/questions/8779027/bind-result-not-getting-all-results

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!