function serializeKeyArrayAndSendToDB($receivingUser)
{
echo "<br />Entered serializeKeyArray<br />"; //This is successful
include $_SERVER['DOCUMENT_ROOT'] . '/includes/DB.inc.php';
$serializedCharacterList = serialize($this->characterList);
echo "Done serializing characterlist: $serializedCharacterList <br />"; //Successful
$this->messageID = $this->generateKeyID(); //Generate-a 8 character ID
echo "MessageID for the keyArray: $this->messageID <br />"; //Successful
//Check whether this ID exists in the database already
try
{
echo "Hi.<br />"; //successful
$sql = 'SELECT COUNT(*) FROM TranslationKeys WHERE ID = :ID';
$s = $pdo->prepare($sql);
$s->bindValue(':ID', $this->messageID);
$s->execute();
$result = $s->fetchAll();
echo "Am I getting the ID for TranslationKeys at all?<br />"; //This is NOT printed
//If there is a matching ID in the database already
if ($result[0][0] > 0)
{
$this->messageID = $this->generateKeyID();
$this->serializeKeyArrayAndSendToDB();
}
}
catch (PDOException $e)
{
echo "Error message: " . $e->getMessage() . "<br />";
}
try
{
$sql = 'INSERT INTO TranslationKeys(ID, keyArray, receivingUserEmail) VALUES(:ID, :serializedKeyArray, :receivingUserEmail)';
$s = $pdo->prepare($sql);
$s->bindValue(':ID', $this->messageID);
$s->bindValue(':serializedKeyArray', $serializedCharacterList);
$s->bindValue(':receivingUserEmail', $receivingUser);
$s->execute();
echo "Here I've attempted to insert into TranslationKeys<br />"; //Fails
}
catch (PDOException $e)
{
echo "Error message: " . $e->getMessage() . "<br />";
//Handle later
}
}
I've added comments for each line I echo, saying whether it was successful or not. It's worth noting that the variable $pdo is the database connection, which I receive via the include on top (from db.inc.php). On the server that file is located in www/includes/db.inc.php, so I believe my include line should be successful. I also use similar code for the connection for the login on the program, and that works just fine. But something fails here and I can't quite put my finger on it.

New Topic/Question
Reply



MultiQuote





|