Back to index

php5  5.3.10
Static Public Member Functions
MySQLPDOTest Class Reference
Inheritance diagram for MySQLPDOTest:
Inheritance graph
[legend]
Collaboration diagram for MySQLPDOTest:
Collaboration graph
[legend]

List of all members.

Static Public Member Functions

static factory ($classname= 'PDO', $drop_test_tables=false, $myattr=null, $mydsn=null)
static createTestTable ($db, $engine=null)
static getTableEngine ()
static getDSN ($new_options=null, $addition= '')
static getClientVersion ($db)
static getServerVersion ($db)
static extractVersion ($version_string)
static getTempDir ()
static detect_transactional_mysql_engine ($db)
static isPDOMySQLnd ()
static dropTestTable ($db=NULL)
static factory ($classname= 'PDO', $drop_test_tables=true)
static skip ()
static test_factory ($file)

Detailed Description

Definition at line 5 of file mysql_pdo_test.inc.


Member Function Documentation

static MySQLPDOTest::createTestTable ( db,
engine = null 
) [static]

Definition at line 35 of file mysql_pdo_test.inc.

                                                            {
              if (!$engine)
                     $engine = PDO_MYSQL_TEST_ENGINE;

              $db->exec('DROP TABLE IF EXISTS test');
              $db->exec('CREATE TABLE test(id INT, label CHAR(1), PRIMARY KEY(id)) ENGINE=' . $engine);
              $db->exec("INSERT INTO test(id, label) VALUES (1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e'), (6, 'f')");
       }

Definition at line 144 of file mysql_pdo_test.inc.

                                                              {              
              foreach ($db->query("show variables like 'have%'") as $row) {
                     if (!empty($row) && $row[1] == 'YES' && ($row[0] == 'have_innodb' || $row[0] == 'have_bdb')) {
                            return str_replace("have_", "", $row[0]);
                     }
              }
              /* MySQL 5.6.1+ */
              foreach ($db->query("SHOW ENGINES") as $row) {
                     if (isset($row['engine']) && isset($row['support'])) {
                             if ('InnoDB' == $row['engine'] && ('YES' == $row['support'] || 'DEFAULT' == $row['support']))
                                   return 'innodb';
                     }
              }
              return false;
       }
static MySQLPDOTest::dropTestTable ( db = NULL) [static]

Definition at line 169 of file mysql_pdo_test.inc.

                                                 {
              if (is_null($db))
                     $db = self::factory();

              $db->exec('DROP TABLE IF EXISTS test');
       }

Here is the call graph for this function:

static MySQLPDOTest::extractVersion ( version_string) [static]

Definition at line 90 of file mysql_pdo_test.inc.

                                                       {
              /*
              TODO:
              We're a bit in trouble: PDO_MYSQL returns version strings.
              That's wrong according to the manual. According to the manual
              integers should be returned. However, this code needs to work
              with stinky PDO_MYSQL and hopefully better PDO_MYSQLND.
              */

              // already an int value?
              if (is_int($version_string))
                     return $version_string;

              // string but int value?
              $tmp = (int)$version_string;
              if (((string)$tmp) === $version_string)
                     return $tmp;

              // stinky string which we need to parse
              $parts = explode('.', $version_string);
              if (count($parts) != 3)
                     return -1;

              $version = (int)$parts[0] * 10000;
              $version+= (int)$parts[1] * 100;
              $version+= (int)$parts[2];

              return $version;
       }

Here is the caller graph for this function:

static MySQLPDOTest::factory ( classname = 'PDO',
drop_test_tables = false,
myattr = null,
mydsn = null 
) [static]

Definition at line 7 of file mysql_pdo_test.inc.

                                                                                                             {

              $dsn   = self::getDSN($mydsn);
              $user  = PDO_MYSQL_TEST_USER;
              $pass  = PDO_MYSQL_TEST_PASS;
              $attr  = getenv('PDOTEST_ATTR');

              if (is_string($attr) && strlen($attr)) {
                     $attr = unserialize($attr);
              } else {
                     $attr = null;
              }
              if ($user === false)
                     $user = NULL;
              if ($pass === false)
                     $pass = NULL;

              $db = new $classname($dsn, $user, $pass, $attr);
              if (!$db) {
                     die("Could not create PDO object (DSN=$dsn, user=$user)\n");
              }

              $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
              $db->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);

              return $db;
       }

Here is the call graph for this function:

Here is the caller graph for this function:

static PDOTest::factory ( classname = 'PDO',
drop_test_tables = true 
) [static, inherited]

Definition at line 22 of file pdo_test.inc.

                                                                             {
              $dsn = getenv('PDOTEST_DSN');
              $user = getenv('PDOTEST_USER');
              $pass = getenv('PDOTEST_PASS');
              $attr = getenv('PDOTEST_ATTR');
              if (is_string($attr) && strlen($attr)) {
                     $attr = unserialize($attr);
              } else {
                     $attr = null;
              }

              if ($user === false) $user = NULL;
              if ($pass === false) $pass = NULL;

              $db = new $classname($dsn, $user, $pass, $attr);

              if (!$db) {
                     die("Could not create PDO object (DSN=$dsn, user=$user)\n");
              }

              // clean up any crufty test tables we might have left behind
              // on a previous run
              static $test_tables = array(
                     'test',
                     'test2',
                     'classtypes'
                     );
              if ($drop_test_tables) {
                     foreach ($test_tables as $table) {
                            $db->exec("DROP TABLE $table");
                     }
              }

              $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
              $db->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
              $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
              return $db;
       }

Here is the caller graph for this function:

static MySQLPDOTest::getClientVersion ( db) [static]

Definition at line 82 of file mysql_pdo_test.inc.

                                             {
              return self::extractVersion($db->getAttribute(PDO::ATTR_CLIENT_VERSION));
       }

Here is the call graph for this function:

static MySQLPDOTest::getDSN ( new_options = null,
addition = '' 
) [static]

Definition at line 49 of file mysql_pdo_test.inc.

                                                                   {
              if (!$new_options)
                     return PDO_MYSQL_TEST_DSN . $addition;

              $old_options = array();
              $dsn = substr(PDO_MYSQL_TEST_DSN,
                     strpos(PDO_MYSQL_TEST_DSN, ':') + 1,
                     strlen(PDO_MYSQL_TEST_DSN));

              // no real parser - any excotic setting can fool us
              $parts = explode(';', $dsn);
              foreach ($parts as $k => $v) {
                     $tmp = explode('=', $v);
                     if (count($tmp) == 2)
                            $old_options[$tmp[0]] = $tmp[1];
              }

              $options = $old_options;
              foreach ($new_options as $k => $v)
                     $options[$k] = $v;

              $dsn = 'mysql:';
              foreach ($options as $k => $v)
                     $dsn .= sprintf('%s=%s;', $k, $v);

              if ($addition)
                     $dsn .= $addition;
              else
                     $dsn = substr($dsn, 0, strlen($dsn) -1);

              return $dsn;
       }

Here is the caller graph for this function:

static MySQLPDOTest::getServerVersion ( db) [static]

Definition at line 86 of file mysql_pdo_test.inc.

                                             {
              return self::extractVersion($db->getAttribute(PDO::ATTR_SERVER_VERSION));
       }

Here is the call graph for this function:

static MySQLPDOTest::getTableEngine ( ) [static]

Definition at line 44 of file mysql_pdo_test.inc.

                                        {
              return PDO_MYSQL_TEST_ENGINE;
       }
static MySQLPDOTest::getTempDir ( ) [static]

Definition at line 120 of file mysql_pdo_test.inc.

                                    {

              if (!function_exists('sys_get_temp_dir')) {

                     if (!empty($_ENV['TMP']))
                            return realpath( $_ENV['TMP'] );
                     if (!empty($_ENV['TMPDIR']))
                            return realpath( $_ENV['TMPDIR'] );
                     if (!empty($_ENV['TEMP']))
                            return realpath( $_ENV['TEMP'] );

                     $temp_file = tempnam(md5(uniqid(rand(), TRUE)), '');
                     if ($temp_file) {
                            $temp_dir = realpath(dirname($temp_file));
                            unlink($temp_file);
                            return $temp_dir;
                     }
                     return FALSE;
              } else {
                     return sys_get_temp_dir();
              }

       }

Here is the call graph for this function:

static MySQLPDOTest::isPDOMySQLnd ( ) [static]

Definition at line 160 of file mysql_pdo_test.inc.

                                      {
                     ob_start();
                     phpinfo();
                     $tmp = ob_get_contents();
                     ob_end_clean();
                     $tmp = stristr($tmp, "PDO Driver for MySQL => enabled");
                     return (bool)preg_match('/Client API version.*mysqlnd/', $tmp);
       }
static PDOTest::skip ( ) [static, inherited]

Definition at line 61 of file pdo_test.inc.

                              {
              try {
                     $db = PDOTest::factory();
              } catch (PDOException $e) {
                     die("skip " . $e->getMessage());
              }
       }

Here is the call graph for this function:

static PDOTest::test_factory ( file) [static, inherited]

Definition at line 69 of file pdo_test.inc.

                                           {
              $data = file_get_contents($file);
              $data = preg_replace('/^.*--REDIRECTTEST--/s', '', $data);
              $config = eval($data);
              foreach ($config['ENV'] as $k => $v) {
                     putenv("$k=$v");
              }
              return self::factory();
       }

Here is the call graph for this function:


The documentation for this class was generated from the following file: