我有一个包含公司徽标的表....每当我读到像 4096字节这样的小图片时它工作得很好,但我无法读取 10000字节在PHP中。 它只能从数据库中读取 4096字节
更新
Sql中的列Lenth:
模型中的我的代码
function GetLogoById($Id)
{
$this->load->database();
mssql_query("SET TEXTSIZE 2147483647");
// or use CI's active record
$this->db->query("SET TEXTSIZE 2147483647");
$query = $this->db->query( "EXEC GetLogoById '$Id'" );
$result = array();
foreach ($query->result() as $row)
{
$result[] = array("Logo"=> $row->Logo);
}
return $result;
}
我的控制器代码:
public function GetLogoById()
{
parse_str($_SERVER['QUERY_STRING'],$_GET);
$Id = $_GET['Id'];
$this->load->model('MyModel');
$result = $this->MyModel->GetLogoById($Id);
header('Content-type: image/png');
echo $result[0]['Logo'];
}
我只获得4096字节,如:(string:4096) ����
我在浏览器上收到此错误:
答案 0 :(得分:2)
我认为这是使用MSSQL的问题,其中存储在文本类型列中的数据在4096个字符后被截断没有明显的原因。
增加从SQL Server返回的文本列的最大大小。您可以使用以下SQL查询执行此操作:
SET TEXTSIZE 2147483647
您可以使用以下PHP运行它,在建立连接后立即运行它:
mssql_query("SET TEXTSIZE 2147483647");
// or use CI's active record
$this->db->query("SET TEXTSIZE 2147483647");
另一种解决此问题的方法是更改php.ini中的“textlimit”和“textsize”设置,如下所示:
mssql.textlimit = 2147483647
mssql.textsize = 2147483647
请参阅此回答Why TEXT column returns only 4096 bytes?,其中提及SQL Server, PHP and Truncating Text。
更新:在进一步审核后,请阅读this PHP bug,您可能希望尝试使用PDO_ODBC
连接到MSSQL Server:
//$dsn = 'mssql:host=MYBOX;dbname=testdb';
$dsn = 'odbc:DRIVER={SQL Server};SERVER=MYBOX;DATABASE=testdb;';
还尝试将TEXTSIZE
设置为兆字节:
$sql = "SET TEXTSIZE 3145728"; // 3 Megabytes
mssql_query($sql, $db) or die(mssql_get_last_message());
答案 1 :(得分:2)
获得sqlsrv
驱动程序的解决方案;)
function GetLogoById($Id)
{
$serverName = "XXXXX";
$uid = "XXXXXX";
$pwd = "XXXXXX";
$connectionInfo = array( "UID"=>$uid,
"PWD"=>$pwd,
"Database"=>"XXXXXX");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
$tsql = "select Logo from TableName where Id = '$Id'";
$stmt = sqlsrv_query( $conn, $tsql);
if( $stmt === false)
{
echo "Error in query preparation/execution.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Retrieve each row as an associative array and display the results.*/
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC))
{
return $row;
}
/* Free statement and connection resources. */
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
}
答案 2 :(得分:0)
首先。不要使用DBMS来存储图像。相信我。
其次,请勿使用DMBS存储图像.....
现在,如果您从模型中获取$ id,为什么循环代码返回数组?有什么打败了id的目的?
我假设徽标数据以BLOB的形式存储?
如果是这种情况,模型可能类似于:
$query = $this->db->get_where('tablename',array('id' => $id));
if ($query->num_rows() == 1)
{
return $query->first_row()->logo
}
else
{
return FALSE;
}
然后控制器代码可能是这样的:
public function GetLogoById($id)
{
$this->load->model('MyModel');
if($logo = $this->MyModel->GetLogoById($id))
{
$this->output->set_content_type('image/png');
$this->output->set_output($logo);
}
}