[ Index ]
 

Code source de SPIP Agora 1.4

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/Pear/tests/driver/ -> mktable.inc (source)

   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.14 2004/04/29 23:20:24 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  
  58  switch ($type) {
  59      case 'access':
  60          $null = 'NULL';
  61          $chrc = 'VARCHAR(255)';
  62          $chrd = 'VARCHAR(20)';
  63          $default = '';
  64          $tabletype = '';
  65          break;
  66      case 'db2':
  67      case 'ibase':
  68          $null = '';
  69          $chrc = 'VARCHAR(255)';
  70          $chrd = 'VARCHAR(20)';
  71          $default = "DEFAULT 'def' NOT NULL";
  72          $tabletype = '';
  73          break;
  74      case 'msql':
  75      case 'ifx':
  76          // doing this for ifx to keep certain versions happy
  77          $null = '';
  78          $chrc = 'CHAR(255)';
  79          $chrd = 'CHAR(20)';
  80          $default = "DEFAULT 'def' NOT NULL";
  81          $tabletype = '';
  82          break;
  83      case 'mysql':
  84      case 'mysqli':
  85          $null = 'NULL';
  86          $chrc = 'VARCHAR(255)';
  87          $chrd = 'VARCHAR(20)';
  88          $default = "DEFAULT 'def' NOT NULL";
  89          if (!empty($needinnodb)) {
  90              $tabletype = 'TYPE=INNODB';
  91          } else {
  92              $tabletype = '';
  93          }
  94          break;
  95      default:
  96          $null = 'NULL';
  97          $chrc = 'VARCHAR(255)';
  98          $chrd = 'VARCHAR(20)';
  99          $default = "DEFAULT 'def' NOT NULL";
 100          $tabletype = '';
 101  }
 102  
 103  
 104  $test_mktable_query = "
 105      CREATE TABLE phptest (
 106        a INTEGER $null,
 107        b CHAR(40) $default,
 108        c $chrc $null,
 109        d $chrd $null) $tabletype
 110  ";
 111  
 112  
 113  $dbh->query($test_mktable_query);
 114  $dbh->query("INSERT INTO phptest VALUES(42, 'bing', 'This is a test', '1999-11-21')");
 115  
 116  $dbh->setErrorHandling(PEAR_ERROR_RETURN);
 117  
 118  ?>


Généré le : Sat Feb 24 14:40:03 2007 par Balluche grâce à PHPXref 0.7