6 Replies - 469 Views - Last Post: 19 January 2013 - 12:35 AM Rate Topic: -----

#1 agsgt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-May 12

Problem with PHP and PL/SQL

Posted 18 January 2013 - 06:07 PM

Good night, I need some help with my code because i cant get the output from the sql funcion to the table, i´ve looking in the php manual for solutions but i cant resolve this problem
<?php

  $stmt = oci_parse ($conn, "begin PQUESTOES.P12(:Q_FOR_NIF,:Q_For_Nome, :Q_For_Morada, :Q_For_Localidade, :Q_For_CodigoPostal, :Q_For_Telefone, :Q_For_Fax, :Q_For_Email, :Q_For_Telemovel,:error,:errorMsg); end;");
  oci_bind_by_name($stmt,":Q_For_NIF",$_REQUEST["q_for_nif"]);
  oci_bind_by_name($stmt,":Q_For_Nome",$q_for_nome,512);
  oci_bind_by_name($stmt,":Q_For_Morada",$q_for_morada,512);
  oci_bind_by_name($stmt,":Q_For_Localidade",$p_for_localidade,512);
  oci_bind_by_name($stmt,":Q_For_CodigoPostal",$p_for_codigopostal,512);
  oci_bind_by_name($stmt,":Q_For_Telefone",$p_for_telefone,512);
  oci_bind_by_name($stmt,":Q_For_Fax",$p_for_fax,512);
  oci_bind_by_name($stmt,":Q_For_Email",$p_for_email,512);
  oci_bind_by_name($stmt,":Q_For_Telemovel",$p_for_telemovel,512);
  oci_bind_by_name($stmt,":error",$error,3);
  oci_bind_by_name($stmt,":errorMsg",$errorMsg,512);
  oci_execute($stmt);
  
  if ($error != 0) {
    echo "<h2 class=\"erro\">Erro: $errorMsg</h2>";
  }
  else {
        echo "
<table> 
<tr>
<th>For_Nome</th>
<th>For_Morada</th>
<th>For_Localidade</th>
<th>For_CodigoPostal</th>
<th>For_Telefone</th>
<th>For_Fax</th>
<th>For_Email</th>
<th>For_Telemovel</th>
</tr>";

echo "
<tr>
<td>$q_for_nome->FOR_NOME</td>
<td>$q_for_morada->FOR_MORADA</td>
<td>$p_for_localidade->FOR_LOCALIDADE</td>
<td>$p_for_codigopostal->FOR_CODIGOPOSTAL</td>
<td>$p_for_telefone->FOR_TELEFONE</td>
<td>$p_for_fax->FOR_FAX</td>
<td>$p_for_email->FOR_EMAIL</td>
<td>$p_for_telemovel->FOR_TELEMOVEL</td>
</tr>";

echo 
"</table>";
  }
  oci_free_statement($stmt);

  oci_close($conn);
  
?>


any help is welcome

This post has been edited by macosxnerd101: 18 January 2013 - 06:10 PM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Problem with PHP and PL/SQL

#2 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3326
  • View blog
  • Posts: 11,248
  • Joined: 12-December 12

Re: Problem with PHP and PL/SQL

Posted 18 January 2013 - 07:04 PM

You've executed the statement but you haven't fetched the data. Something like:

oci_execute($stmt);

while (($row = oci_fetch_array($stmt, OCI_BOTH))) {
    // Use the uppercase column names for the associative array indices
    echo $row[0] . " and " . $row['DEPARTMENT_ID']   . " are the same<br>\n";
    echo $row[1] . " and " . $row['DEPARTMENT_NAME'] . " are the same<br>\n";
}

..assuming your function returns data.

THE DOCS

I'm not 100% sure though, as I don't use oci.

This post has been edited by andrewsw: 18 January 2013 - 07:08 PM

Was This Post Helpful? 0
  • +
  • -

#3 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3716
  • View blog
  • Posts: 5,976
  • Joined: 08-June 10

Re: Problem with PHP and PL/SQL

Posted 18 January 2013 - 07:50 PM

I don't get why you do $q_for_nome->FOR_NOME when printing the OUT parameters. What types are these variables supposed to be?

If you var_dump one of the out variables, say $q_for_nome, right after the execute command, what does it show?

View Postandrewsw, on 19 January 2013 - 02:04 AM, said:

You've executed the statement but you haven't fetched the data.

He wouldn't have to. What he's doing is using two-way variable binding. The variables he's binding to the procedure parameters will be filled by the procedure and returned to PHP. There is no need to read the result set in the "normal" way to do this.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3326
  • View blog
  • Posts: 11,248
  • Joined: 12-December 12

Re: Problem with PHP and PL/SQL

Posted 18 January 2013 - 07:58 PM

@Atli. Thank you.
Was This Post Helpful? 0
  • +
  • -

#5 agsgt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-May 12

Re: Problem with PHP and PL/SQL

Posted 18 January 2013 - 08:16 PM

I have excuted de code with the var_dump and now it shows me null, i am starting to tinhk that the in variable (Q_FOR_NIF) isnt working
<?php

  $stmt = oci_parse ($conn, "begin PQUESTOES.P12(:Q_FOR_NIF,:Q_FOR_NOME, :Q_FOR_MORADA, :Q_FOR_LOCALIDADE, :Q_FOR_CODIGOPOSTAL, :Q_FOR_TELEFONE, :Q_FOR_FAX, :Q_FOR_EMAIL, :Q_FOR_TELEMOVEL); end;");
  oci_bind_by_name($stmt,":Q_FOR_NIF",$_REQUEST["q_for_nif"]);
  oci_bind_by_name($stmt,":Q_FOR_NOME",$q_for_nome,512);
  oci_bind_by_name($stmt,":Q_FOR_MORADA",$q_for_morada,512);
  oci_bind_by_name($stmt,":Q_FOR_LOCALIDADE",$p_for_localidade,512);
  oci_bind_by_name($stmt,":Q_FOR_CODIGOPOSTAL",$p_for_codigopostal,512);
  oci_bind_by_name($stmt,":Q_FOR_TELEFONE",$p_for_telefone,512);
  oci_bind_by_name($stmt,":Q_FOR_FAX",$p_for_fax,512);
  oci_bind_by_name($stmt,":Q_FOR_EMAIL",$p_for_email,512);
  oci_bind_by_name($stmt,":Q_FOR_TELEMOVEL",$p_for_telemovel,512);

  oci_execute($stmt);
       
var_dump ($q_for_nome,$q_for_morada,$p_for_localidade,$p_for_codigopostal,$p_for_telefone,$p_for_fax,$p_for_email,$p_for_telemovel); 

 
  oci_free_statement($stmt);

  oci_close($conn);
  
?>


This post has been edited by macosxnerd101: 18 January 2013 - 08:45 PM
Reason for edit:: Please use code tags

Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10444
  • View blog
  • Posts: 38,682
  • Joined: 27-December 08

Re: Problem with PHP and PL/SQL

Posted 18 January 2013 - 08:45 PM

Please use code tags: :code:.
Was This Post Helpful? 0
  • +
  • -

#7 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3716
  • View blog
  • Posts: 5,976
  • Joined: 08-June 10

Re: Problem with PHP and PL/SQL

Posted 19 January 2013 - 12:35 AM

What is the value of $_REQUEST["q_for_nif"] before you put it into the statement? You don't have any sort of validation in place to verify that it has a valid value, or even any value at all, so your script is completely at the user's mercy.

You should always make sure input values are valid before using them, and handle it properly when that's not the case. (By printing and/or logging error messages, or using a default value instead.)

The isset and empty functions can come in hand with that, as well as the filter_input function.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1