$serv = "xxx";
$user = "xxx";
$pass = "xxx";
$db = "xxx";
$imgloc = "../images/bg.jpg";
$image = fopen($imgloc, 'rb');
$imageContent = fread($image, filesize($imgloc));
$conn = new mysqli($serv, $user, $pass, $db);
$sql = "INSERT INTO `image`(`advert_id`,`img`) VALUES('1','" . $imageContent . "');";
$conn->query($sql);
我正在使用上面的代码尝试向我的MySQL数据库中插入二进制文件,但没有任何内容正在发送到数据库。 $ imageContent仅在数据库中显示为空,但如果我回显$ imageContent,它似乎显示二进制数据。将二进制插入到MySQL BLOB
advert_id只是一个INT领域和IMG是BLOB
你很容易受到[SQL注入攻击(http://bobby-tables.com )。你不能只是随机二进制垃圾到查询字符串,并期望事情工作。 –
http://php.net/manual/en/mysqli.prepare.php和http://php.net/manual/en/mysqli-stmt.bind-param.php – AbraCadaver
我应该使用哪些函数来清除它? –