首页 文章

PHP MySQL SELECT文本被截断

提问于
浏览
2

我有一个MySQL表,其中包含'text'类型的'full_description'列 . 在该列中是标准的lorem ipsum(加上单词END):

Lorem ipsum dolor sit amet,consectetur adipisicing elit,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua . Ut enim ad minim veniam,quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat . Duis aute irure dolor in repreptderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur . Excepteur sint occaecat cupidatat non proident,sunt in culpa qui officia deserunt mollit anim id est laborum . 结束

然而,当在php中对它进行选择时,它只检索了这么多:

Lorem ipsum dolor sit amet,consectetur adipisicing elit,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua . Ut enim ad minim veniam,quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat . Duis aute irure dolor i

这是检索它的PHP代码:

function getPostingDetails($posting_id){
        $getPosting = $this->PLAST->prepare('SELECT posting_id, poster_id, title, short_description, full_description FROM postings WHERE posting_id=?');
        $getPosting->bind_param('i',$posting_id);
        $getPosting->execute();
        $getPosting->bind_result($row['posting_id'],$row['poster_id'],$row['title'],$row['short_description'],$row['full_description']);
        $getPosting->fetch();
        $getPosting->close();
        return $row;        
    }

这是我得到的数组:

Array ( [posting_id] => 1 [poster_id] => 1 [title] => Test 1 [short_description] => This is a short description. [full_description] => Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor i )

其余的田地都很好 . 我究竟做错了什么?或者是否有一个我不知道的限制SELECT语句的设置或功能?在MySQL?在PHP mysqli?

谢谢

这是根据请求的表结构:

CREATE TABLE `postings` (
  `posting_id` int(11) NOT NULL AUTO_INCREMENT,
  `poster_id` int(11) NOT NULL,
  `title` tinytext NOT NULL,
  `short_description` tinytext NOT NULL,
  `full_description` text NOT NULL,
  PRIMARY KEY (`posting_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1

4 回答

  • 0

    你使用的框架是什么?我认为这是数据类型TEXT的一些默认限制 .

    框架我指的是访问数据库的PHP库:

    $getPosting->bind_param(...);
        $getPosting->execute();
        $getPosting->bind_result(...);
        $getPosting->fetch();
        $getPosting->close();
    

    以上是来自某些库的功能 . 最可能的是该库对TEXT字段的长度有默认限制 .

    EDITED:

    我发现SQL Server和PHP here有类似的问题 . 他们建议这样做:

    SELECT CAST(F AS TEXT) AS F FROM
    

    也许你可以做相反的事情:

    SELECT ..., CAST(full_description AS VARCHAR) FROM postings
    
  • 0

    尝试在获取并将其存储在php之前初始化一个空字符串....我有一个类似的问题,它只存储字符串的第一个字母,但是当我在存储之前初始化var时,它工作了

  • 0

    如果您使用实际变量,而不是使用数组来存储结果,它会有什么不同,例如将其替换为: $getPosting->bind_result($row['posting_id'],$row['poster_id'],$row['title'],$row['short_description'],$row['full_description']);$getPosting->bind_result($posting_id,$poster_id,$title,$short_description,$full_description); 看看是否有任何区别?

  • 0

    我在使用group_concat时遇到了类似的问题,并为group_concat设置了最大长度帮助了我 . 刚刚在我的select查询之前执行了此查询 .

    SET GROUP_CONCAT_MAX_LEN = 10000;

相关问题