home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / mktable.inc < prev    next >
Encoding:
Text File  |  2004-03-24  |  2.4 KB  |  101 lines

  1. <?php
  2.  
  3. /**
  4.  * Creates the <kbd>phptest</kbd> table.
  5.  *
  6.  * Tries to drop the table first, in case it already exists.
  7.  *
  8.  * <pre>
  9.  * CREATE TABLE phptest (
  10.  *   a INTEGER NULL,
  11.  *   b CHAR(40) DEFAULT 'def' NOT NULL,
  12.  *   c VARCHAR(255) NULL,
  13.  *   d VARCHAR(20) NULL)
  14.  * </pre>
  15.  *
  16.  * Need <kbd>NOT NULL</kbd> on <kbd>b</kbd> to test
  17.  * <kbd>DB_PORTABILITY_RTRIM</kbd>.  MS SQL and Sybase trim output from
  18.  * <kbd>VARCHAR</kbd>, but not on <kbd>CHAR</kbd>.
  19.  *
  20.  * Need <kbd>DEFAULT</kbd> value on <kbd>b</kbd> because Oracle considers
  21.  * an empty string to be <kbd>NULL</kbd>.
  22.  *
  23.  * In Oracle, when using placeholders in <kbd>WHERE</kbd> clauses on 
  24.  * <kbd>CHAR</kbd> columns, the column must have <kbd>RTRIM()</kbd> run on
  25.  * the column:
  26.  * <samp>
  27.  *    SELECT * FROM phptest WHERE RTRIM(b) = ?
  28.  * </samp>
  29.  *
  30.  * @package  DB
  31.  * @version $Id: mktable.inc,v 1.13 2004/02/08 00:08:41 danielc Exp $
  32.  * @category Database
  33.  * @internal
  34.  */
  35.  
  36. /**
  37.  * Establishes the DB object and connects to the database.
  38.  */
  39. require_once './connect.inc';
  40.  
  41. $dbh->setErrorHandling(PEAR_ERROR_RETURN);
  42. $dbh->query("DROP TABLE phptest");
  43.  
  44. //$dbh->setErrorHandling(PEAR_ERROR_TRIGGER);
  45. $dbh->setErrorHandling(PEAR_ERROR_CALLBACK, 'debug_die');
  46.  
  47. if ($dbh->phptype == 'odbc') {
  48.     if ($dbh->dbsyntax == 'odbc') {
  49.         $type = $dbh->phptype;
  50.     } else {
  51.         $type = $dbh->dbsyntax;
  52.     }
  53. } else {
  54.     $type = $dbh->phptype;
  55. }
  56.  
  57. switch ($type) {
  58.     case 'access':
  59.         $null = 'NULL';
  60.         $chrc = 'VARCHAR(255)';
  61.         $chrd = 'VARCHAR(20)';
  62.         $default = '';
  63.         break;
  64.     case 'db2':
  65.     case 'ibase':
  66.         $null = '';
  67.         $chrc = 'VARCHAR(255)';
  68.         $chrd = 'VARCHAR(20)';
  69.         $default = "DEFAULT 'def' NOT NULL";
  70.         break;
  71.     case 'msql':
  72.     case 'ifx':
  73.         // doing this for ifx to keep certain versions happy
  74.         $null = '';
  75.         $chrc = 'CHAR(255)';
  76.         $chrd = 'CHAR(20)';
  77.         $default = "DEFAULT 'def' NOT NULL";
  78.         break;
  79.     default:
  80.         $null = 'NULL';
  81.         $chrc = 'VARCHAR(255)';
  82.         $chrd = 'VARCHAR(20)';
  83.         $default = "DEFAULT 'def' NOT NULL";
  84. }
  85.  
  86. $test_mktable_query = "
  87.     CREATE TABLE phptest (
  88.       a INTEGER $null,
  89.       b CHAR(40) $default,
  90.       c $chrc $null,
  91.       d $chrd $null)
  92. ";
  93.  
  94.  
  95. $dbh->query($test_mktable_query);
  96. $dbh->query("INSERT INTO phptest VALUES(42, 'bing', 'This is a test', '1999-11-21')");
  97.  
  98. $dbh->setErrorHandling(PEAR_ERROR_RETURN);
  99.  
  100. ?>
  101.