1

I am developing a simple money tracking web app on my Mac using SQLite and PHP. I am having a problem inserting data into the sqlite db using parameters with the insert statement. This is not a permissions problem because I have been able to write a static insert statement and it executes properly. Here is my code:

try
{
$databaseins = new PDO("sqlite:/datastores/trackmoney.db")  or die("Could not open database"); 
$databaseins->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO Transactions 
    (TransactionID, TransactionName, Expense, Description, TransactionDate, DateEntered, RecordedBy) 
VALUES (:TransactionID,:TransactionName,:Expense,:Description,:TransactionDate,:DateEntered,:RecordedBy);";
// below is a static insert that works
//$sql = "INSERT INTO Transactions (TransactionID, TransactionName, Expense, Description, TransactionDate, DateEntered, RecordedBy) VALUES ('$guidTransactionID','Test',12.12,'test','3/2/2012','12/12/2012',1);";
$q = $databaseins->prepare($sql);
$q->bindParam(':TransactionID', $guidTransactionID, SQLITE3_TEXT);
$q->bindParam(':TransactionName', $strTransName, SQLITE3_TEXT);
$q->bindParam(':Expense', $fltTransAmount, SQLITE3_FLOAT);
$q->bindParam(':Description', $strTransDescrip, SQLITE3_BLOB);
$q->bindParam(':TransactionDate', $strDateOfTrans, SQLITE3_TEXT);
$q->bindParam(':DateEntered', "1/1/2013", SQLITE3_TEXT);
$q->bindParam(':RecordedBy', 1, SQLITE3_INTEGER);

$count = $q->execute() or die($databaseins->errorInfo());
print("<b>" + $count + "</b>");
$databaseins = null;
}
catch(PDOException $e)
{
echo $e->getMessage();//this getMessage throws an exception if any 
}

I do not receive any error messages. Note, that all of the values of the variables are set and have a value.

Thanks for any help.

3
  • 2
    Might you need to use bindValue, rather than bindParam? Commented Sep 5, 2012 at 20:22
  • 2
    What if you change the SQLITE3_BLOB for SQLITE3_TEXT? Commented Sep 5, 2012 at 20:23
  • You were both right. I changed to bindValue and changed the SQLITE3_BLOB to SQLITE3_TEXT and it all works wonderful now! Thank! Commented Sep 5, 2012 at 20:37

1 Answer 1

2

Thanks to andrewsi and JvdBerg for your help. The fix to my problem was to use bindValue instead of bindParam and change SQLITE3_BLOB to SQLITE3_TEXT.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.