Can someone please help me. I am trying to save the picture taken by the camera using the example provided by NSBApp Studion examples(Which is just the greatest product!) using the following Function and PHP code but it is just not saving the image or ID to the database The id is an Int and content is LongBlob
Function AddImageToDB_onclick()
Dim postData
postData = postData & "&imgBase64=" & encodeURIComponent(PictureBox3.toDataURL())
req=Ajax("/TestImage.php/?myText=" & postData)
If req.status=200 Then 'success
MsgBox(req.responseText)
Else
MsgBox(req.responseText)
End If
End Function
<?php
$base64_data= $_GET['myText'];
$dbhost = 'localhost'; //MySQL database is located on your server
$dbname = 'db'; //the name of your database
$dbuser = 'db'; // your user ID for the database
$dbpass = 'ghhggghhgh$'; // your password for the database
$link = mysqli_connect($dbhost, $dbuser, $dbpass, $db_name);
if (mysqli_connect_errno($link)) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$stmt = mysqli_prepare($link, "INSERT INTO test (id, content) VALUES (?, ?)");
$stmt->bind_param('ib', $id, $content);
$id = 1;
$content = null;
$stmt->send_long_data(1, $base64_data );
mysqli_stmt_execute($stmt);
//printf("%d Row inserted.\n", mysqli_stmt_affected_rows($stmt));
mysqli_stmt_close($stmt);
?>:
$base64_data= $_GET['myText'];
$dbhost = 'localhost'; //MySQL database is located on your server
$dbname = 'db'; //the name of your database
$dbuser = 'db'; // your user ID for the database
$dbpass = 'ghhggghhgh$'; // your password for the database
$link = mysqli_connect($dbhost, $dbuser, $dbpass, $db_name);
if (mysqli_connect_errno($link)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); }
$stmt = mysqli_prepare($link, "INSERT INTO test (id, content) VALUES (?, ?)");
$stmt->bind_param('ib', $id, $content);
$id = 1;
$content = null;
$stmt->send_long_data(1, $base64_data );
mysqli_stmt_execute($stmt);
//printf("%d Row inserted.\n", mysqli_stmt_affected_rows($stmt)); mysqli_stmt_close($stmt);
Perhaps storing the photo on the database is not the most practical idea. Because of the following reasons:
The databases with the hosting are normally limited to 1 gb, but generally gives you more space (50, 80, 160 gb) to store files.
If you store the photo in a table with more comumns than the photo, if for some reason for a record a photo is not added the record size will still be huge since the record separates the blob the size.
3.everytime you need go retrieve the photo you will need to enter to the database AnD that consumes time. Then you should convert the image so it can travel back, and then the client should convert the received data to jpg or png. This add more time to this process.
My recomendation is that you receive the information of the picture, then you generate a .jpg or .png file on the server and in the database only store the name of the file.
Now, whenever you need to retrive the photo you just call the file.