By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,216 Members | 1,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,216 IT Pros & Developers. It's quick & easy.

Prepared SQL query not working with PEAR::MDB2 and SQL Server Express

P: n/a
Hi, I wonder If somebody has experience this or could point me in the
right direction:

I have the following script (commented out just to use the username):

// Check username and password
// Assume you have a valid DB handler ($dbh) already connected
$result = false;
if ( isset($_POST['username']) && isset($_POST['password']) ) {
$username = $_POST['username'];
// $password = $_POST['password'];
echo "username: $username<br>\n";
//echo "password: $password<br>\n";

$result =& $dbh->query($WEBAPP_LOGIN_SQL, $username);

if (PEAR::isError($result)) {
echo "An error occurred while trying to execute the
following
query:<br>\n";
echo "$WEBAPP_LOGIN_SQL<br>\n";
echo "Error message: " . $result->getMessage() . "<br>\n";
echo "A more detailed error description: " . $result-
>getDebugInfo() . "<br>\n";
exit();
}

}

The query in the global variable $WEBAPP_LOGIN_SQL is:
$WEBAPP_LOGIN_SQL = "select UserKey from [User] where UserName = ?";
Unfortunately I get the following output:

username: lll
An error occurred while trying to execute the following query:
select UserKey from [User] where UserName = ?
Error message: MDB2 Error: syntax error
A more detailed error description: _doQuery: [Error message: Could not
execute statement] [Last executed query: select UserKey from [User]
where UserName = ?] [Native code: 102] [Native message: Incorrect
syntax near '?'.]

I tried also passing an array as the second argument to the query
method but I get the same result.

I will appreciate any useful feedback.
Thanks.

Feb 22 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
sa********@gmail.com wrote:
Hi, I wonder If somebody has experience this or could point me in the
right direction:

I have the following script (commented out just to use the username):

// Check username and password
// Assume you have a valid DB handler ($dbh) already connected
$result = false;
if ( isset($_POST['username']) && isset($_POST['password']) ) {
$username = $_POST['username'];
// $password = $_POST['password'];
echo "username: $username<br>\n";
//echo "password: $password<br>\n";

$result =& $dbh->query($WEBAPP_LOGIN_SQL, $username);

if (PEAR::isError($result)) {
echo "An error occurred while trying to execute the
following
query:<br>\n";
echo "$WEBAPP_LOGIN_SQL<br>\n";
echo "Error message: " . $result->getMessage() . "<br>\n";
echo "A more detailed error description: " . $result-
>getDebugInfo() . "<br>\n";

exit();
}

}

The query in the global variable $WEBAPP_LOGIN_SQL is:
$WEBAPP_LOGIN_SQL = "select UserKey from [User] where UserName = ?";
Unfortunately I get the following output:

username: lll
An error occurred while trying to execute the following query:
select UserKey from [User] where UserName = ?
Error message: MDB2 Error: syntax error
A more detailed error description: _doQuery: [Error message: Could not
execute statement] [Last executed query: select UserKey from [User]
where UserName = ?] [Native code: 102] [Native message: Incorrect
syntax near '?'.]

I tried also passing an array as the second argument to the query
method but I get the same result.

I will appreciate any useful feedback.
Thanks.
What's the data type of UserName (in the database)?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 23 '07 #2

P: n/a
Rik
<sa********@gmail.comwrote:
$result =& $dbh->query($WEBAPP_LOGIN_SQL, $username);
I'm not a MDB2 user, but shouldn't that be:
$statement = $dbh->prepare($WEBAPP_LOGIN_SQL);
$result = $statement->execute($username);

Or does the MDB2 query method know you want a statement automagically?
--
Rik Wasmus
Feb 23 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.