Records do not return in PHP

Support_38
Support_38 used Ask the Experts™
on
Good Morning.

I have an incident portal in PHP and am with the following problem:

I have a select when run in ORACLE, the various records are listed, but the PHP page does not return all records.

The problem is probably the while, but I do not know why in PHP only a few records are listed.

Attached PHP code and the result in Oracle.

In this example, the PHP page is not bringing any records, but in the ORACLE has a record that should be showing.

Thank you.
grid_global_soc3.php
Capturar.PNG
Capturar2.PNG
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2016

Commented:
I'm going to make a few recommendations - none are "directly" related to the question, but all will help you move forward on this task, and in your career.

First, please learn about coding standards, adopt one, and use it without fail all of the time.  The lack of consistent spacing and indentation makes the code very hard to read and understand.

Second, please take some time to learn the fundamentals of how to use HTML and PHP.  W3Schools is good for HTML learning.  We have an article here at E-E that can help you learn PHP.  One of the things that jumps out at me is that the script does not test for success or failure, nor does it elevate error messages.  How do you know that oci_execute() worked?  Your script must test the return values.  This is all documented in the online manuals.

Third, please learn about the SSCCE.  It teaches us the right way to ask a question here, and it's the right way to pursue problem resolution.  In this method we eliminate all of the extraneous stuff and isolate the minimum necessary code that demonstrates the problem.

Fourth, please learn about Test-Driven Development.  This appears to be a data-dependent problem, but there is no test data posted with the question.  In most professional development shops, programmers will write the test cases first, using predictable test data sets, before they start writing the code to solve the problems.  The test cases enable us to prove that the code is correct, and to avoid regressions when we must extend or refactor a code base.

To try to come to grips with the query, here is what I might do.  First, go into the code attachment at line 91 and test for success or failure of the query.  Visualize any error messages.  Next, at line 94 insert this statement, and eliminate the rest of the script.  This will let you see the query results without any conditional code or formatting that might interfere with an understanding.
var_dump($resultado); }

Open in new window

HTH, ~Ray
Most Valuable Expert 2012
Distinguished Expert 2018
Commented:
First:  I don't know anything about PHP.

I do know Oracle.  I notice the row you are looking for has Unicode characters in it.

I wonder if it is a characterset encoding mismatch between the client and server.

Oracle typically needs to set NLS_LANG on the client side to properly handle conversion between the client and server correctly.

I'll let Ray deal with the PHP specifics since he is the PHP Expert.

Until he posts back a quick web search provided:
https://community.oracle.com/thread/476322?start=0&tstart=0
Most Valuable Expert 2011
Top Expert 2016

Commented:
I don't know anything about Oracle, but you're in good hands with SlightWV on that front.

For a better understanding of character encoding issues, you might find this article useful.  It talks about MySQL, but some of the same principles may apply to Oracle, too.
http://iconoun.com/articles/collisions/
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Hello

I appreciate the recommendations.

I'm not a developer, I am of the database area but need to implement this portal.

This code was initially written for Windows using ODBC connection, I had to export it to linux, but I have not found a way to make the connection to the database by ODBC in linux, the only way I found worked and was utiliando OCI

What is harder to understand is that some records are shown in php, some not, but is not filter problem in select, because when I direct select the PL-SQL records are displayed correctly.

Thank you.
Most Valuable Expert 2012
Distinguished Expert 2018

Commented:
>>What is harder to understand is that some records are shown in php, some not, but is not filter problem in select, because when I direct select the PL-SQL records are displayed correctly.


This is what makes me think it is a characterset encoding issue.  The tool you are using to directly query the database is encoding the characters properly and it is able to find them.

If PHP isn't encoding them properly, what is being passed to the database aren't the same characters you think they are which is why the row isn't found.
Most Valuable Expert 2011
Top Expert 2016

Commented:
See the fourth connection parameter here:
http://php.net/manual/en/function.oci-connect.php
character_set

    Determines the character set used by the Oracle Client libraries. The character set does not need to match the character set used by the database. If it doesn't match, Oracle will do its best to convert data to and from the database character set. Depending on the character sets this may not give usable results. Conversion also adds some time overhead.

    If not specified, the Oracle Client libraries determine a character set from the NLS_LANG environment variable.

    Passing this parameter can reduce the time taken to connect.
My guess is that this parameter must be correct and consistent for writing as well as for reading.  Your PHP script needs these statements if you're using UTF-8.
mb_internal_encoding('UTF-8');
mb_regex_encoding('UTF-8');
mb_http_output('UTF-8');

Open in new window

Author

Commented:
Hi

Actually the problem was in Unicode.

To solve the problem, it was added AL32UTF8 command in the connection string as shown below:

$ Conn = oci_connect (username, pass, $ tns2, 'AL32UTF8')

Thank you all

Author

Commented:
Thank you for your help

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial