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.

4

1 に答える 1

2

andrewsi と JvdBerg の助けに感謝します。私の問題の修正は、bindParam の代わりに bindValue を使用し、SQLITE3_BLOB を SQLITE3_TEXT に変更することでした。

于 2012-09-05T20:39:36.183 に答える