This question already has answers here:
Calculating total data size of BLOB column in a table
(4 answers)
Closed 8 years ago.
i have a table where i am saving images as blob
now the issue is, how can i get the size of the blob in each tuple.
is there any query to do so?
Try
SELECT OCTET_LENGTH(blob_content) FROM test_blob WHERE id = 1
Use SELECT OCTET_LENGTH(blob_tablename) FROM...
Related
This question already has answers here:
Images in MySQL
(5 answers)
Closed 6 months ago.
I'm trying to store an image in a MySQL database with the use of PHP. What is the datatype that I should use?
You can store the base64 string of the image in your table.
$img_file = "/tmp/my_image.jpg";
// get base64 string
$imgData = base64_encode(file_get_contents($img_file));
// insert into DB
$dbh->prepare("INSERT INTO my_image_table (img_base64) VALUES(?)");
$dbh->execute(array($imgData));
Make sure your data type of the column is big enough for the images. LONGTEXT can save up to 4GB.
Alternative: use BLOB or file-paths like others suggested.
This question already has answers here:
When to use VARCHAR and DATE/DATETIME
(5 answers)
Closed 2 years ago.
I have a table that holds few records less than 20. The table (cow_inactive) is just with ID (int) & COW_INACTIVE_DATE (varchar) columns. I am trying to use the DATEDIFF to get all cows that are ready for insemination after 60 Days of being inactive.
SELECT * from cow_inactive where DATEDIFF(CURRENT_DATE, inactive_date)>=60
Result :
Showing rows 0 - 0 (1 total, Query took 0.0022 seconds.)
you need to update field data type COW_INACTIVE_DATE (DATETIME). then run above query
This question already has answers here:
SQL select only rows with max value on a column [duplicate]
(27 answers)
Retrieving the last record in each group - MySQL
(33 answers)
Closed 3 years ago.
I have a problem to show one of duplicate data with last created date. This is is my query :
$sqlpur ="SELECT DISTINCT pn, created_date, id_purchase FROM pur_supp ORDER BY pn, created_date DESC";
This is the result.
This is a data from database.
But, I want to show just one of duplicate data. an example just to show 02N64073 with last created Date.
This question already has answers here:
How to retrieve the last 4 characters from a mysql database field?
(4 answers)
Getting last 5 char of string with mysql query
(6 answers)
Query to select strings end with certain character
(6 answers)
Closed 5 years ago.
this is my data in the database and i'm using mysql
database image
How do I retreive number "4" from the data using sql command?
USE reverse and left
set #myfield = 1234;
select left(reverse(#myfield),1) as result;
result
4
demo here
http://rextester.com/LTBE34983
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to get Insert id in MSSQL in PHP?
I MYSQL I would do
SHOW TABLE STATUS LIKE 'image'
In mssql, sigh, I've no idea how to do it...
Please advice.. :)
You can try this to get the NEXT identity.
SELECT IDENT_CURRENT('image') + IDENT_INCR('image')
You can use this:
SELECT IDENT_CURRENT ('image')
then add 1 to get the next.
It's better than using max(id)+1 because the latest id might have been deleted
You could use the max value +1. Something like
Select max(id)+1 from image;