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.
<?php
$myusername=$_POST['user'];
echo $myusername;
$mypassword=$_POST['pass'];
$db = new SQLite3('capT.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
$statement = $db->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:
<?php
$myusername=$_POST['user'];
echo $myusername;
$mypassword=$_POST['pass'];
$db = new SQLite3('capT.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
$statement = $db->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.
's'
when you have no such parameter? Also see stackoverflow.com/a/5077108/14868997