public function testForceMysql() { if (!function_exists('mysql_connect')) { $this->markTestIncomplete("mysql_* isn't available on this PHP build."); } if ($mysqlDeprecated = version_compare(PHP_VERSION, '5.5.0') >= 0) { error_reporting(error_reporting() & ~E_DEPRECATED); } $this->tearDown(); $this->_amysql = new AMysql(); $this->_amysql->setConnDetails(array('host' => AMYSQL_TEST_HOST, 'username' => AMYSQL_TEST_USER, 'password' => AMYSQL_TEST_PASS, 'port' => 3306, 'db' => AMYSQL_TEST_DB)); AMysql_Abstract::$useMysqli = false; $this->createTable(); $this->assertEquals('resource', gettype($this->_amysql->link)); AMysql_Abstract::$useMysqli = true; if ($mysqlDeprecated) { error_reporting(error_reporting() | E_DEPRECATED); } }
/** * @constructor * @param resource|mysqli|array|string $resOrArrayOrHost (Optional) Either a valid mysql or mysqli connection * resource/object, or a connection details array * as according to setConnDetails() (doesn't auto connect), * or parameters you would normally pass to the mysql_connect() * function. (auto connects) * (NOTE that this last construction method is * discouraged and may be deprecated and removed in later versions) * (Also note that I mention the arguments mysql_connect(), but only * the arguments. This library will still connect to mysqli if it * is available) * * @see $this->setConnDetails() * @see $this->setConnDetails() * **/ public function __construct($resOrArrayOrHost = null, $username = null, $password = null, $newLink = false, $clientFlags = 0) { if (!class_exists('AMysql_Statement')) { // Assume no autoloader, and load everything manually $dir = dirname(realpath(__FILE__)); require_once $dir . '/Exception.php'; require_once $dir . '/Expr.php'; require_once $dir . '/Statement.php'; require_once $dir . '/Iterator.php'; require_once $dir . '/Select.php'; require_once $dir . '/Profiler.php'; } $this->setAutoPingSeconds($this->autoPingSeconds); // Use mysqli by default if available and PHP is at least of version 5.3.0 (required). // Can be overridden by connection details. self::$useMysqli = class_exists('Mysqli', false) && function_exists('mysqli_stmt_get_result'); if (is_resource($resOrArrayOrHost) && 0 === strpos(get_resource_type($resOrArrayOrHost), 'mysql link')) { $this->link = $resOrArrayOrHost; $this->isMysqli = false; } elseif ($resOrArrayOrHost instanceof Mysqli) { $this->link = $resOrArrayOrHost; $this->isMysqli = true; } elseif (is_array($resOrArrayOrHost)) { $this->setConnDetails($resOrArrayOrHost); } elseif (is_string($resOrArrayOrHost)) { $this->oldSetConnDetails($resOrArrayOrHost, $username, $password, $newLink, $clientFlags); $this->connect(); } }