Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP][Oracle] - problem z blob-em
Forum PHP.pl > Forum > PHP
Okto
Witam,
chciałem skorzystać z trywialnej stronki za pomocą której mógłbym ładować zdjęcia do bazy oracle i niestety się nie udaje poniżej kod i dwa błędy no i prośba o pomoc :


  1.  
  2. // filename: uploadimage3-form.php
  3.  
  4. <HEAD><TITLE>Store binary data into SQL Database</TITLE></HEAD>
  5.  
  6. <form method="post" action="uploadimage3.php" enctype="multipart/form-data">
  7. File Description:<br>
  8. <input type="text" name="id" size="40">
  9. <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000000">
  10. <br>File to upload/store in database:<br>
  11. <input type="file" name="file_data" size="40">
  12. <p><input type="submit" name="submit" value="submit">
  13. </form>
  14.  
  15. </BODY>
  16. </HTML>




  1. <?php
  2.  
  3. // filename: uploadimage3.php
  4.  
  5. $username = 'CRI';
  6. $password = 'CRI';
  7. $dbname = 'IP/CBI';
  8.  
  9.  
  10.  
  11. echo $_POST['submit'];
  12.  
  13. if(array_key_exists('submit',$_POST))
  14. {
  15.  
  16. echo "tmp_name : ".$tmpfilename = $_FILES['file_data']['tmp_name'];
  17. print "<br>\n\t";
  18. echo "filesize : ".$filesize = filesize($tmpfilename);
  19. print "<br>\n\t";
  20. echo "filetype : ".$filetype = $_FILES['file_data']['type'];
  21. print "<br>\n\t";
  22. echo "filename : ".$filename = $_FILES['file_data']['name'];
  23. print "<br>\n\t";
  24. //echo "descript : ".$file_description = $_POST['file_description'];
  25. //print "<br>\n\t";
  26. echo "id : ".$id = $_POST['id'];
  27. print "<br>\n\t";
  28.  
  29. $data = addslashes(fread(fopen($tmpfilename, "r"), $filesize));
  30. //$data = (fread(fopen($form_data, "r"), filesize($form_data)));
  31. //You have to pass Appropriate username, Password,Serveice name
  32. $db = OCILogon($username, $password, $dbname);
  33.  
  34.  
  35.  
  36. $stmt = OCIParse($db,"INSERT INTO BLOB_TABLE VALUES($id,EMPTY_BLOB()) returning id,IMG into :id,:lob");
  37. $lob = OCINewDescriptor($db);
  38. OCIBindByName($stmt,":ID",$id,32);
  39. OCIBindByName($stmt,":LOB",$lob,-1,SQLT_BLOB);
  40. // we cannot use autocommitt here
  41. $exec_result=OCIExecute($stmt,OCI_DEFAULT);
  42. $lob->save($data);
  43. //echo "$form_data id:$id\n";
  44. OCICommit($db);
  45. if(!$exec_result)
  46. {
  47. print "Error Occured".OCIError($db);
  48. }else{
  49. OCICommit ($db);
  50. print "<p>This file has been uploaded into Database ";
  51. }
  52. }
  53. ?>




PHP Warning: ociexecute() [<a href='function.ociexecute'>function.ociexecute</a>]: ORA-00904: &quot;IMG&quot;: niepoprawny identyfikator in uploadimage3.php on line 36
PHP Warning: OCI-Lob::save() [<a href='oci-lob.save'>oci-lob.save</a>]: OCI_INVALID_HANDLE in uploadimage3.php on line 37






No i nie wstawia.

PHP 5.3.3; Oracle 11g; oci8 version: 1.4.1

krowal
Ja bym stawiał na OCIlogon() -> http://php.net/manual/pl/function.ocilogon.php niewskazane jest jej używanie przy php wyższym niż 5.0, zamiast tego spróbuj oci_connect() i zobacz czy faktycznie nawiązuje poprawnie połączenie, a jeśli nie to jaki błąd zwraca.
Okto
Oczywiście zmieniłem, lecz nadal w logu dwa zapisy:

  1. <?php
  2.  
  3. $username = 'CRI';
  4. $password = 'CRI';
  5. $dbname = '10.160.80.30/CBI';
  6.  
  7.  
  8.  
  9.  
  10. echo $_POST['submit'];
  11.  
  12. if(array_key_exists('submit',$_POST))
  13. {
  14.  
  15. echo "tmp_name : ".$tmpfilename = $_FILES['file_data']['tmp_name'];
  16. print "<br>\n\t";
  17. echo "filesize : ".$filesize = filesize($tmpfilename);
  18. print "<br>\n\t";
  19. echo "filetype : ".$filetype = $_FILES['file_data']['type'];
  20. print "<br>\n\t";
  21. echo "filename : ".$filename = $_FILES['file_data']['name'];
  22. print "<br>\n\t";
  23. //echo "descript : ".$file_description = $_POST['file_description'];
  24. //print "<br>\n\t";
  25. echo "id : ".$id = $_POST['id'];
  26. print "<br>\n\t";
  27.  
  28. $data = addslashes(fread(fopen($tmpfilename, "r"), $filesize));
  29. //$data = (fread(fopen($form_data, "r"), filesize($form_data)));
  30. //You have to pass Appropriate username, Password,Serveice name
  31. //$db = OCILogon($username, $password, $dbname);
  32. $db = oci_connect($username, $password, $dbname) or die('Błąd połączenia');
  33. //$db = oci_connect($username, $password, $dbname);
  34. $stmt = OCIParse($db,"INSERT INTO BLOB_TABLE VALUES($id,EMPTY_BLOB()) returning id,IMG into :id,:lob");
  35. $lob = OCINewDescriptor($db);
  36. OCIBindByName($stmt,":ID",$id,32);
  37. OCIBindByName($stmt,":LOB",$lob,-1,SQLT_BLOB);
  38. // we cannot use autocommitt here
  39. $exec_result=OCIExecute($stmt,OCI_DEFAULT);
  40. $lob->save($data);
  41. //echo "$form_data id:$id\n";
  42. OCICommit($db);
  43. if(!$exec_result)
  44. {
  45. print "Error Occured".OCIError($db);
  46. }
  47. else
  48. {
  49. OCICommit ($db);
  50. print "<p>This file has been uploaded into Database ";
  51. }
  52.  
  53.  
  54. oci_free_statement($stmt);
  55.  
  56. oci_close($db);
  57. }
  58. ?>
  59.  


[12-Dec-2010 09:48:26] PHP Warning: ociexecute() [<a href='function.ociexecute'>function.ociexecute</a>]: ORA-00904: &quot;IMG&quot;: niepoprawny identyfikator in uploadimage3.php on line 39
[12-Dec-2010 09:48:26] PHP Warning: OCI-Lob::save() [<a href='oci-lob.save'>oci-lob.save</a>]: OCI_INVALID_HANDLE in uploadimage3.php on line 40


Po kilku modyfikacjach udało mi się uzyskać dodatkowy zapis z błędem:

[12-Dec-2010 15:42:25] PHP Fatal error: Zapytanie zakończyło się niepowodzeniem: ORA-00904: "IMG": niepoprawny identyfikator in uploadimage3.php on line 46
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.