我在数据库中保存了一个json字符串,它似乎在SQL Server中正确存储,但是当尝试获取数据时,它只返回json字符串的一部分。
我正在使用PDO和json_encode来保存数据。 存储的json字符串长约1000个字符,表字段允许长度为4096。
获取结果:
$sql = "SELECT TOP 1 * FROM MyTable WHERE id = :id ORDER BY id DESC;";
$params = array(
":id" => $id
);
$sth = $this->db->prepare($sql);
$sth->execute($params);
$result = $sth->fetch(PDO::FETCH_ASSOC);
保存结果:
$json = json_encode($_POST);
$sql = "INSERT INTO MyTable(data) VALUES (:data);";
$params = array(
":data" => $data
);
$stmt = $this->db->prepare($sql);
$stmt->execute($params);
存储在SQL Server中的示例Json:
{
"checkbox_1":"on",
"checkbox_2":"on",
"checkbox_3":"on",
"text_1":"my text",
"images":[
13685
],
"date":"11-11-2015"
}
示例Json返回:
{
"checkbox_1":"on",
"checkbox_2":"on",
"checkbox_3":"on",
"text_1
更新
看来返回的字符串长度始终为: 255
这可能是SQL Server配置还是PDO?
答案 0 :(得分:1)
事实证明,当从varchar列获取时,我用于通过PDO连接到SQL Server的协议限制为255个字符。
解决方法是将列更改为TEXT或将其转换为SQL
中的文本app.controller('EventController', function($scope){
$scope.score1 = 0;
$scope.score2 = 0;
$scope.playing = true;
$scope.win1 = false;
$scope.lose1 = false;
$scope.win2 = false;
$scope.lose2 = false;
//Counter
$scope.counter = 0;
$scope.totalScore = $scope.score1 + $scope.score2;
$scope.player1 = " Player 1";
$scope.player2 = " Player 2";
$scope.currentplayer = $scope.player1;
$scope.switchplayer = function(){
if ($scope.counter % 2 === 0){
if($scope.totalScore % 2 === 0){
$scope.currentplayer = $scope.player2;
} else {
$scope.currentplayer = $scope.player1;
}
}};
$scope.incrementScore1 = function() {
$scope.score1++;
$scope.counter++;
if ($scope.score1 === 11){
$scope.playing = false;
$scope.win1 = true;
$scope.lose2 = true;
console.log('Player 1 wins!');
}
};
$scope.incrementScore2 = function() {
$scope.score2++;
$scope.counter++;
if ($scope.score2 == 11){
$scope.playing = false;
$scope.win2 = true;
$scope.lose1 = true;
console.log('Player 2 wins!');
}
};
$scope.reset = function(){
$scope.score1='0';
$scope.score2='0';
$scope.playing = true;
$scope.win1 = false;
$scope.lose1 = false;
$scope.win2 = false;
$scope.lose2 = false;
};
});
<div class="container" ng-controller='EventController'>
<h1>Score Keeper</h1>
<h3>Current Serve:<span>{{currentplayer}}</span></h3>
<div class="row" ng-class="{'current': playing}">
<div class="col-md-6" ng-click='incrementScore1();switchplayer()' ng-model='score1' ng-class="{'win1': win1, 'lose1': lose1}">
<p>{{score1}}</p><br><br><br>
</div>
<div class="col-md-6" ng-model='score2' ng-click='incrementScore2();switchplayer()' ng-class="{'win2': win2, 'lose2': lose2}">
<p>{{score2}}</p><br><br><br>
</div>
</div>
<button ng-click='reset()'>Reset</button>
</div>
ODBC query on MS SQL Server returning first 255 characters only in PHP PDO (FreeTDS)
答案 1 :(得分:0)
编辑:看起来OP的问题是其他问题,但我会将此问题留给未来可能有类似问题的人,可以通过查看TEXTSIZE
来解决。
看起来问题可能出在SQL Server中的TEXTSIZE
变量,它通过PHP限制了返回文本的长度。
查看当前使用的值
SELECT @@TEXTSIZE
并使用
将其更新为更高的值SET TEXTSIZE 2147483647
其中数字是最大字符数(默认为/ maxes out at the above value)。
以下是TEXTSIZE
:https://msdn.microsoft.com/en-us/library/ms186238.aspx