You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
3.3 KiB

  1. <HTML>
  2. <HEAD>
  3. <TITLE>Database test #5</TITLE>
  4. </HEAD>
  5. <BODY>
  6. <H1>ODBC Test 5 - Blobs</H1>
  7. <?php
  8. if(!isset($gif1file) && !isset($display) ||
  9. ($gif1file == "none" && $gif2file == "none"
  10. && $gif3file == "none")){
  11. ?>
  12. <H2>Please select the images (gif) you want to put into the database</H2>
  13. <FORM METHOD="POST" ACTION="<?php echo $PHP_SELF ?>" ENCTYPE="multipart/form-data">
  14. Image 1: <INPUT TYPE="file" NAME="gif1file" VALUE="" SIZE="48"><P>
  15. Image 2: <INPUT TYPE="file" NAME="gif2file" VALUE="" SIZE="48"><P>
  16. Image 3: <INPUT TYPE="file" NAME="gif3file" VALUE="" SIZE="48"><P>
  17. Blob database type name: <INPUT TYPE="text" NAME="datatype" VALUE="LONG BYTE" SIZE="32">
  18. <P>
  19. <INPUT TYPE="hidden" name="dsn" value="<?php echo $dsn ?>">
  20. <INPUT TYPE="hidden" name="dbuser" value="<?php echo $dbuser ?>">
  21. <INPUT TYPE="hidden" name="dbpwd" value="<?php echo $dbpwd ?>">
  22. <INPUT TYPE="submit" VALUE="Send File(s)">
  23. | <INPUT TYPE="reset" VALUE="reset">
  24. </FORM>
  25. </BODY>
  26. </HTML>
  27. <?php
  28. exit;
  29. }
  30. if(isset($dbuser)){
  31. echo "Connecting to $dsn as $dbuser\n";
  32. $conn = odbc_connect($dsn, $dbuser, $dbpwd);
  33. if(!$conn){
  34. ?>
  35. <H2>Error connecting to database! Check DSN, username and password</H2>
  36. <?php
  37. }else{
  38. ?>
  39. - OK<p>
  40. <?php
  41. if(isset($display)){
  42. if(($res = odbc_exec($conn, 'select id from php_test'))){
  43. echo "<H3>Images in database</H3>";
  44. while(odbc_fetch_into($res, &$imgs)){
  45. echo "$imgs[0] : <IMG SRC=\"odbc-display.php?id=$imgs[0]&dbuser=$dbuser&dsn=$dsn&dbpwd=$dbpwd\">\n<P>";
  46. }
  47. }else{
  48. echo "Couldn't execute query";
  49. }
  50. echo "\n</BODY>\n</HTML>";
  51. exit;
  52. }
  53. ?>
  54. Dropping table "php_test"
  55. <?php
  56. Error_Reporting(0);
  57. $res = odbc_exec($conn, "drop table php_test");
  58. if($res){
  59. odbc_free_result($res);
  60. }
  61. ?>
  62. - OK<p>
  63. Creating table "php_test":
  64. <?php
  65. $res = odbc_exec($conn, "create table php_test (id char(32), gif $datatype)");
  66. if($res){
  67. odbc_free_result($res);
  68. ?>
  69. - OK<p>
  70. Table Info:<br>
  71. <table>
  72. <tr>
  73. <th>Name</th>
  74. <th>Type</th>
  75. <th>Length</th>
  76. </tr>
  77. <?php
  78. $info = odbc_exec($conn,"select * from php_test");
  79. $numfields = odbc_num_fields($info);
  80. for($i=1; $i<=$numfields; $i++){
  81. ?>
  82. <tr>
  83. <td><?php echo odbc_field_name($info, $i) ?></td>
  84. <td><?php echo odbc_field_type($info, $i) ?></td>
  85. <td><?php echo odbc_field_len($info,$i) ?></td>
  86. </tr>
  87. <?php
  88. }
  89. odbc_free_result($info);
  90. ?>
  91. </table>
  92. Inserting data:
  93. <?php
  94. echo "$gif1file - $gif2file - $gif3file";
  95. odbc_free_result($res);
  96. $res = odbc_prepare($conn, "insert into php_test values(?,?)");
  97. if($gif1file != "none"){
  98. $params[0] = "image1";
  99. $params[1] = "'$gif1file'";
  100. odbc_execute($res, $params);
  101. }
  102. if($gif2file != "none"){
  103. $params[0] = "image2";
  104. $params[1] = "'$gif2file'";
  105. odbc_execute($res, $params);
  106. }
  107. if($gif3file != "none"){
  108. $params[0] = "image3";
  109. $params[1] = "'$gif3file'";
  110. odbc_execute($res, $params);
  111. }
  112. ?>
  113. - OK<P>
  114. <A HREF="<?php echo "$PHP_SELF?display=y&dbuser=$dbuser&dsn=$dsn&dbpwd=$dbpwd" ?>">Display Images</A>
  115. <?php
  116. }
  117. }
  118. } else {
  119. ?>
  120. <form action=odbc-t5.php method=post>
  121. <table border=0>
  122. <tr><td>Database: </td><td><input type=text name=dsn></td></tr>
  123. <tr><td>User: </td><td><input type=text name=dbuser></td></tr>
  124. <tr><td>Password: </td><td><input type=password name=dbpwd></td></tr>
  125. </table>
  126. <input type=submit value=connect>
  127. </form>
  128. <?php
  129. }
  130. ?>
  131. </BODY>
  132. </HTML>