Reputation: 318
Good day everybody.
I have searched for hours on a reson for the way php behaves with a query that I have with no avail.. any assistance would be appreciated.
I am creating a simple application where the customer will sign on a tablet and the signiture need to be stored in the db along with other order details as a proof of delivery.
The image field datatype is BLOB.
While storing an image in the database is not the best way to go, it is a part of the requirements so there is no way around it. The signature is stored correctly in the database, using MySQL workbench viewer to retrieve the data actually shows the Base64 image string, and when it is copied and placed within a <img>
tag it displays correctly.
When I try to query the database to retrieve the image I get "Warning: Invalid argument supplied for foreach()" which means that I have an error in the sql statement. When I use the same query in phpMyAdmin or MySQL Workbench I get results.
The query I use is as follows:
$order_details_stmt = $db->query("SELECT *
FROM dms_dl_delivery_details
WHERE `way_bill_number` = '$waybill_no'");
foreach($order_details_stmt as $row3){
$signature = $row3['reciepient_signature'];
$invoice_book = $row3['reciept_book'];
$invoice_no = $row3['reciept_no'];
$recieved_by = $row3['recieved_by'];
}
To echo the signature I use <img src="<?php echo $signature; ?>">
, but I don't even get there. If I do var_dump($order_details_stmt);
I get boolean false, however, all the other variables I get from the query work fine: $invoice_book, $invoice_no, and $recieved_by are echoed correctly in the output page.
the table create statement is as follows:
CREATE TABLE `dms_dl_delivery_details` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`way_bill_number` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
`sender_customer_id` varchar(16) COLLATE utf8_unicode_ci NOT NULL,
`way_bill_date_time` datetime NOT NULL,
`pick_up_address_id` varchar(13) COLLATE utf8_unicode_ci NOT NULL,
`reciepient_signature` blob NOT NULL,
`reciept_book` char(4) COLLATE utf8_unicode_ci NOT NULL,
`reciept_no` char(4) COLLATE utf8_unicode_ci NOT NULL,
`recieved_by` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `way_bill_number_UNIQUE` (`way_bill_number`)
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8
COLLATE=utf8_unicode_ci;
I'm using PHP 5.4.12 and MySQL 5.6.12
Any thoughts on what am I doing wrong here?
Thanks!
Upvotes: 2
Views: 494
Reputation: 33935
What happens if you use the prepare-execute method...
$stm = $dbh->prepare($sql);
$stm->execute();
$result = $stm->fetchAll();
foreach (
Upvotes: 0
Reputation: 920
it should look like this
$result = $db->query("SELECT *
FROM dms_dl_delivery_details
WHERE `way_bill_number` = '$waybill_no'");
$order_details_stmt = $result->fetchAll();
Upvotes: 1