Hello, I'm trying to launch this query:
If I use this code everyting works just fine (I get 152 results):
Let's say I want to use prepared statements:
What I see on my browser after executing this code is:
What should I check in order to make prepared statements work? |
Here's an example that might help. It's similar to what you want to do.
1
@JBSchueler Thank you very much! Everything works now. I prefer using sasql_fetch_assoc instead of sasql_fetch_row, so that I can obtain an associative array in $row with the tables fields as keys (it's more confortable). Just one more question: in most databases (MSSSQL, Postgre, MySql, etc...) I can use prep stmts with labels instead of "?" question marks (ie.: "....WHERE id = :productID"). Then I bind every param like for example: stmt_bind(':productID', $_POST['product_id'], SQL_INT); Is there a way to obtain the same behaviour also on SQLAnywhere? Thank you again very very much!
(18 Apr '14, 12:26)
tzanarella
Replies hidden
Try asking your new question as a new question, you will get more people to pay attention to it.
(18 Apr '14, 12:31)
Breck Carter
|
Is that the actual code?
If so, the prepared statement is in $st, not $a; try this:
$b = sasql_stmt_bind_param($st, 'i', $year);
If that is NOT the actual code, then please post the actual code.
@Breck Thanks for your comment. This is the actual code, actually I made a mistake on copy-paste, but the statement is $a and I get empty results.
What does $b return?
Can you replace the call to sasql_stmt_bind_param() with sasql_stmt_bind_param_ex(), which allows a 1:1 binding of parameters?
(That's all wild guessing...)
$b returns bool(true).
If I change the function to sasql_stmt_bind_param_ex($a, 0, $year, 'i'); nothing changes: it returns bool(true) and 0 results.
Try telling SQL Anywhere to turn on "request level logging" so you can see exactly what the server sees. Assuming you are using version 16, see this Help topic: Request logging
Note that $n = sasql_stmt_next_result($a); skips to the next result set (but you have only one). But that isn't the only issue with the code.
$i = sasql_stmt_num_rows($a);
From the doc: The actual number of rows in the result set can only be determined after the sasql_stmt_store_result function is called to buffer the entire result set. If the sasql_stmt_store_result function has not been called, 0 is returned.
$n = sasql_stmt_next_result($a);
This moves to the next result set. You haven't dealt with the first one (and presumably the only one).