Link to home
Start Free TrialLog in
Avatar of Support_38
Support_38

asked on

Records do not return in PHP

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
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

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
ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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/
Avatar of Support_38
Support_38

ASKER

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.
>>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.
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

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
Thank you for your help