i've read a lot of posts concerning similair problem with utf-8 issues and tried some too but i can't find the cause.
I'm using livecode and i want to encrypt some strings to a database. So i encrypt in Livecode then base64encode then send to database via PHP/PDO. encrypt-->base64encode-->base64decode-->decrypt within livecode works ok.
Now when i send the base64encoded data to the MariaDB database it saves it, except + has become a space. The database, table and columns are all utf8mb4_unicode_ci. If i change the space to + manually via phpmyadmin in the database and read out with Livecode then it base64decodes-->decrypts correct!
This are the php files i use to connect and update the db:
<?php
// the connect.php file
$servername = "localhost";
$username = "blabla";
$password = "blabla";
try {
//$db = new PDO("mysql:host=$servername;dbname=blabla",$username, $password);
$db = new PDO("mysql:host=$servername;dbname=blabla;charset=utf8", $username, $password);
//$db = new PDO("mysql:host=$servername;dbname=blabla;charset=utf8mb4", $username, $password,array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4' COLLATE 'utf8mb4_unicode_ci'"));
// set the PDO error mode to exception
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
?>
you can see i tried some charsets in the connect file also
<?php
//this is the file to update the DB
require_once 'connect.php';
//
try {
$stmt = $db->prepare("UPDATE tabel_users SET user=:user,
password=:password, email=:email, userlevel=:userlevel WHERE
id_user=:id_user");
$stmt->bindParam(':id_user', $_POST['id_user'], PDO::PARAM_INT);
$stmt->bindParam(':user', $_POST['user'], PDO::PARAM_STR);
$stmt->bindParam(':password', $_POST['password'], PDO::PARAM_STR);
$stmt->bindParam(':email', $_POST['email'], PDO::PARAM_STR);
$stmt->bindParam(':userlevel', $_POST['userlevel'], PDO::PARAM_STR);
//$stmt->bindParam(':user', $_POST['user'], PDO::PARAM_LOB);
//$stmt->bindParam(':password', $_POST['password'], PDO::PARAM_LOB);
//$stmt->bindParam(':email', $_POST['email'], PDO::PARAM_LOB);
//$stmt->bindParam(':userlevel', $_POST['userlevel'], PDO::PARAM_LOB);
$affected_rows = $stmt->rowCount();
if($stmt->execute()) { echo "Ge-update informatie verzonden naar de
database!"; } else { echo "Failure!"; };
}
catch(PDOException $e)
{
echo "Not updated: " . $e->getMessage();
}
//var_dump($_POST)
$db = NULL;
?>
Also tried PDO::PARAM_LOB Tried VARCHAR VARBIN BLOB but this did not change a thing.
My first guess was that Livecode does something weird while posting it to the php file. But checking the variable just before it is send has the + in the string to send. So i don't really get it where it goes wrong.