Embedding PHP variable into Sqlite statement
-1
votes
1
answer
256
views
I have been struggling with this for hours. I am pretty new to Sqlite and have been trying to write a prepared statement, everything works up until I try to get my variable in.
The following works as does a direct
SELECT
- entering the string straight in the statement.
prepare('SELECT * FROM Users WHERE Name = ?');
$statement->bindValue(1, 'aName');
$result = $statement->execute();
echo("Get the 1st row as an associative array:\n");
print_r($result->fetchArray(SQLITE3_ASSOC));
echo("\n");
$result->finalize();
However as soon as I bring a variable in to play with bindParam
, I do not get results.
like so:
prepare('SELECT * FROM Users WHERE Name = ?');
$statement->bindParam('s', $myusername);
$result = $statement->execute();
echo("Get the 1st row as an associative array:\n");
print_r($result->fetchArray(SQLITE3_ASSOC));
echo("\n");
$result->finalize();
I have checked the $_POST['user'] variable and it is pulling through. Any help that solves my issue or shows how I might debug would be most welcome.
I am working in PHP Storm just in case there is something specific to that IDE.
I have also tried with Name = :Name
and binding with that.
Thanks in advance.
Asked by fcreav
(99 rep)
Mar 2, 2024, 01:38 AM
Last activity: Mar 3, 2024, 12:25 AM
Last activity: Mar 3, 2024, 12:25 AM