PHP Snippet 1:
<?php
# Only decode $FingerData.
...
$a = base64_decode($FingerData);
...
# Insert data
public function registerCustomer($custId, $custData)
{
...
$sqlString = "INSERT INTO CUSTMASTER (CustId, CustData) VALUES (?, CONVERT(varbinary(max), ?)); SELECT SCOPE_IDENTITY();";
$params = array(
array($custId, SQLSRV_PARAM_IN),
array($custData, SQLSRV_PARAM_IN)
);
$stmt = sqlsrv_query($this->conn, $sqlString, $params);
...
}
?>
PHP Snippet 2:
<?php
#------------------------------
# Connection info
#------------------------------
$server = 'server\instance,port';
$database = 'database';
$uid = 'user';
$pwd = 'password';
#------------------------------
# Connection
#------------------------------
$cinfo = array(
"Database" => $database,
"UID" => $uid,
"PWD" => $pwd
);
$conn = sqlsrv_connect($server, $cinfo);
if( $conn === false )
{
echo "Error (sqlsrv_connect): ".print_r(sqlsrv_errors(), true);
exit;
}
#------------------------------
# Function
#------------------------------
function registerCustomer($connection, $custId, $custData) {
$sqlString = "INSERT INTO CUSTMASTER (CustId, CustData) VALUES (?, CONVERT(varbinary(max), ?)); SELECT SCOPE_IDENTITY();";
$params = array(
array($custId, SQLSRV_PARAM_IN),
array($custData, SQLSRV_PARAM_IN)
);
$stmt = sqlsrv_query($connection, $sqlString, $params);
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
$rows = sqlsrv_has_rows($stmt);
while (sqlsrv_fetch($stmt)) {
$lastId = sqlsrv_get_field($stmt, 0);
}
if ($rows === true) {
echo "Data Inserted.";
} else {
return "Data Insert Failed.";
}
echo $lastId;
}
#------------------------------
# Load image file into database
#------------------------------
# With next two lines I load and encode an image.
# If I understand you correctly, this is already done and you have a base64 encrypted image.
$image = file_get_contents('image.jpg');
$encoded_image = base64_encode($image);
# Insert image
$decoded_image = base64_decode($encoded_image);
registerCustomer($conn, 1, $decoded_image);
?>