× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Jason, was there a leading or trailing blank on your request variable? If so, it would make sense that it would succeed in the non-prepared version, because the SQL parser would ignore multiple spaces in an SQL string when parsing the syntax, whereas the prepared variable gets passed in directly as a variable on its own.


On Oct 31, 2016, at 12:24 PM, Jason Aleski <jason.aleski@xxxxxxxxx <mailto:jason.aleski@xxxxxxxxx>> wrote:

Just figured it out. My column was a 7,0 integer. When I stripped the $_REQUEST variable down to 7 characters, it worked:

$params = array(substr(($_REQUEST['cusnbr']),0,7));

It's weird that it wasn't blowing up on the direct/non-prepared query.

--JA


On 10/31/2016 1:14 PM, Vernon Hamberg wrote:
Jason

The error codes are documented at IBM''s Knowledge Center - have you looked there? Or done a Google on it?

There might also be an SQLCODE - I don't know if php lets you retrieve that, but it should be in the job log, if there is one for this kind of thing.

HTH
Vern

On 10/31/2016 1:01 PM, Jason Aleski wrote:
Pete,

Thanks for the feedback. That's what I'm leaning towards, but it's just odd that I can run the query one way and it works; but not another.

--Todd
On 10/31/2016 12:58 PM, Pete Helgren wrote:
You may want to output the parameter value and see what it is. Something at the back of my head tells me it is a data type mismatch (string for numeric) but I can't rightly remember. PHP is an untyped language but that lack of type can come back to haunt you. I am not sure if this is one of those cases.....

Pete Helgren
www.petesworkshop.com <http://www.petesworkshop.com/>
GIAC Secure Software Programmer-Java
LinkedIn - www.linkedin.com/in/petehelgren
Twitter - Sys_i_Geek IBM_i_Geek

On 10/31/2016 11:50 AM, Jason Aleski wrote:
Attempting to perform a simple select using a PHP and db2_prepared statements. Running the query directly works fine (first part of code). When I run the db2_execute($stmt, $params), I get an error saying "Statement Execute Failed" with a SQL Error Code of 22023. Can anyone see what I'm doing wrong here?

PHP Code Below

<?php
$conn = db2_connect($database, $username, $password, $options);

$sql = "SELECT count(*) FROM CUSTOMERS WHERE acctnbr = ". $_REQUEST['accountNumber'];
$stmt = db2_exec($conn, $sql);
while ($row = db2_fetch_array($stmt)) {
print "$row[0]\n";
}
print "THIS WORKS <hr />";




--
This is the IBMi Open Source Roundtable (OpenSource) mailing list
To post a message email: OpenSource@xxxxxxxxxxxx <mailto:OpenSource@xxxxxxxxxxxx>
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/opensource <http://lists.midrange.com/mailman/listinfo/opensource>
or email: OpenSource-request@xxxxxxxxxxxx <mailto:OpenSource-request@xxxxxxxxxxxx>
Before posting, please take a moment to review the archives
at http://archive.midrange.com/opensource <http://archive.midrange.com/opensource>.



Thanks,
Alan

Alan Seiden
Principal, Seiden Group LLC




Do you get my free PHP newsletter <http://alanseiden.com/tips> ?

Project leader, Zend PHP Toolkit for IBM i
Zend Framework certified contributor

Office: 201-447-2437 Cell: 201-248-4704
http://www.seidengroup.com | alan@xxxxxxxxxxxxxxx
http://twitter.com/alanseiden


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.