简体   繁体   中英

How to store image on database using Php MySql in iOS

I am making one web services part for the app in which i need to store images on database. I have stored name, message and some other information successfully, however for storing images i have used blob, but still what function i need to write for saving.

The best way to store an image in the database is by creating a binary large object column (BLOB) in the table. And then store

<?php
$dbh = mysql_connect("localhost", "user");
mysql_select_db("test");
$data = file_get_contents($image_filename);
// This is important to avoid a ' to accidentally close a string
$data = mysql_real_escape_string($data);
mysql_query("INSERT INTO testblob(data) VALUES ('$data')");
?>

What size are the images you want to store ? I think BLOB's max is 64kb. You may need to use a MEDIUMBLOB column type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM