【问题标题】:writing insert statement for image in php在php中为图像编写插入语句
【发布时间】:2016-07-22 15:19:17
【问题描述】:

我的数据库开发人员为我制作了一个数据库,其中包含 SQL 表中的一个字段作为图像类型。 我正在尝试拍摄某人上传的图像并将其插入。

$imagePath  = Input::file('image');
$image     =  $imagePath->getPathName();

$image 返回临时路径名

$file = fopen($image, "rb");
$content = fread($file, filesize($image));
fclose($file);

$SqlConn =  "INSERT INTO [poll14] ([image]) VALUES ($content)";

但我收到此错误:替换命名参数时发生错误。 我应该如何插入数据?

【问题讨论】:

  • "INSERT INTO poll14 (image) VALUES ('$content')"
  • 您还需要阅读、理解并开始使用参数化查询。您在这里所拥有的对 sql 注入是开放的。

标签: php sql-server laravel laravel-5


【解决方案1】:

试试这个,和你的要求差不多here

insert into poll14 (ImageColumn) 
SELECT BulkColumn 
FROM Openrowset( Bulk 'image..Path..here', Single_Blob) as img

【讨论】:

  • 效果很好。现在如何在存储过程中实现它?
  • @user1899829 你设法让存储过程工作了吗?您忘记接受答案
猜你喜欢
  • 2012-05-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-30
  • 1970-01-01
  • 2017-01-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多