/** * Check settings * * @since PHP 5 */ public function __construct() { if (!PEAR::loadExtension('gd')) { $this->isError(PEAR::raiseError("GD library is not available.", IMAGE_TRANSFORM_ERROR_UNSUPPORTED)); } else { $types = ImageTypes(); if ($types & IMG_PNG) { $this->_supported_image_types['png'] = 'rw'; } if ($types & IMG_GIF || function_exists('imagegif')) { $this->_supported_image_types['gif'] = 'rw'; } elseif (function_exists('imagecreatefromgif')) { $this->_supported_image_types['gif'] = 'r'; } if ($types & IMG_JPG) { $this->_supported_image_types['jpeg'] = 'rw'; } if ($types & IMG_WBMP) { $this->_supported_image_types['wbmp'] = 'rw'; } if (!$this->_supported_image_types) { $this->isError(PEAR::raiseError("No supported image types available", IMAGE_TRANSFORM_ERROR_UNSUPPORTED)); } } }
/** * * */ function Image_Transform_Driver_Imagick() { if (!PEAR::loadExtension('imagick')) { return PEAR::raiseError('The imagick extension can not be found.', true); } include 'Image/Transform/Driver/Imagick/ImageTypes.php'; return true; }
/** * @see http://www.imagemagick.org/www/formats.html */ function __construct() { if (PEAR::loadExtension('imagick')) { include 'Image/Transform/Driver/Imagick/ImageTypes.php'; } else { $this->isError(PEAR::raiseError('Couldn\'t find the imagick extension.', IMAGE_TRANSFORM_ERROR_UNSUPPORTED)); } }
/** * * */ function Image_Transform_Driver_Imagick() { if (!extension_loaded('imagick')) { if (!PEAR::loadExtension('imagick')) { return PEAR::raiseError('The imagick extension can not be found.', true); } } return true; }
/** * Class constructor. Checks that required options * are present and that the SAPRFC extension is loaded * * Options that can be passed and their defaults: * <pre> * array( * 'ASHOST' => "", * 'SYSNR' => "", * 'CLIENT' => "000", * 'GWHOST' =>"", * 'GWSERV' =>"", * 'MSHOST' =>"", * 'R3NAME' =>"", * 'GROUP' =>"", * 'LANG' =>"EN", * 'TRACE' =>"", * 'GETSSO2'=> true * ) * </pre> * * @param array array of options. * @return void */ function Auth_Container_SAP($options) { $saprfc_loaded = PEAR::loadExtension('saprfc'); if (!$saprfc_loaded) { return PEAR::raiseError('Cannot use SAP authentication, ' . 'SAPRFC extension not loaded!'); } if (empty($options['R3NAME']) && empty($options['ASHOST'])) { return PEAR::raiseError('R3NAME or ASHOST required for authentication'); } $this->options = array_merge($this->options, $options); }
function testsetGzip() { $h =& new HTTP_Download(); $this->assertFalse(PEAR::isError($h->setGzip(false)), '$h->setGzip(false)'); $this->assertFalse($h->gzip, '$h->gzip'); if (PEAR::loadExtension('zlib')) { $this->assertFalse(PEAR::isError($h->setGzip(true)), '$h->setGzip(true) without ext/zlib'); $this->assertTrue($h->gzip, '$h->gzip'); } else { $this->assertTrue(PEAR::isError($h->setGzip(true)), '$h->setGzip(true) with ext/zlib'); $this->assertFalse($h->gzip, '$h->gzip'); } unset($h); }
/** * Check settings * * @return mixed true or or a PEAR error object on error * * @see PEAR::isError() */ function __construct() { if (!PEAR::loadExtension('imlib')) { $this->isError(PEAR::raiseError('Couldn\'t find the imlib extension.', IMAGE_TRANSFORM_ERROR_UNSUPPORTED)); } }
/** * Connect to the database * * @return true on success, MDB2 Error Object on failure **/ function connect() { $database_file = $this->_getDatabaseFile($this->database_name); if (is_resource($this->connection)) { if (count(array_diff($this->connected_dsn, $this->dsn)) == 0 && $this->connected_database_name == $database_file && $this->opened_persistent == $this->options['persistent']) { return MDB2_OK; } $this->disconnect(false); } if (!PEAR::loadExtension($this->phptype)) { return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 'extension ' . $this->phptype . ' is not compiled into PHP', __FUNCTION__); } if (!empty($this->database_name)) { if ($database_file !== ':memory:') { if (!file_exists($database_file)) { if (!touch($database_file)) { return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 'Could not create database file', __FUNCTION__); } if (!isset($this->dsn['mode']) || !is_numeric($this->dsn['mode'])) { $mode = 0644; } else { $mode = octdec($this->dsn['mode']); } if (!chmod($database_file, $mode)) { return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 'Could not be chmodded database file', __FUNCTION__); } if (!file_exists($database_file)) { return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 'Could not be found database file', __FUNCTION__); } } if (!is_file($database_file)) { return $this->raiseError(MDB2_ERROR_INVALID, null, null, 'Database is a directory name', __FUNCTION__); } if (!is_readable($database_file)) { return $this->raiseError(MDB2_ERROR_ACCESS_VIOLATION, null, null, 'Could not read database file', __FUNCTION__); } } $connect_function = $this->options['persistent'] ? 'sqlite_popen' : 'sqlite_open'; $php_errormsg = ''; if (version_compare('5.1.0', PHP_VERSION, '>')) { @ini_set('track_errors', true); $connection = @$connect_function($database_file); @ini_restore('track_errors'); } else { $connection = @$connect_function($database_file, 0666, $php_errormsg); } $this->_lasterror = $php_errormsg; if (!$connection) { return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null, 'unable to establish a connection', __FUNCTION__); } if (!empty($this->dsn['charset'])) { $result = $this->setCharset($this->dsn['charset'], $connection); if (PEAR::isError($result)) { return $result; } } $this->connection = $connection; $this->connected_dsn = $this->dsn; $this->connected_database_name = $database_file; $this->opened_persistent = $this->getoption('persistent'); $this->dbsyntax = $this->dsn['dbsyntax'] ? $this->dsn['dbsyntax'] : $this->phptype; } return MDB2_OK; }
// | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Dave Mertens <*****@*****.**> | // +----------------------------------------------------------------------+ // // $Id: Basex.php,v 1.6 2003/06/04 14:48:44 et Exp $ require_once "PEAR.php"; if (!defined('MATH_BASEX_MATHEXTENSION')) { if (PEAR::loadExtension('bcmath')) { define('MATH_BASEX_MATHEXTENSION', 'bcmath'); } elseif (PEAR::loadExtension('gmp')) { define('MATH_BASEX_MATHEXTENSION', 'gmp'); } else { define('MATH_BASEX_MATHEXTENSION', 'none'); } } /** * base X coding class * * I noticed that value of an int is different on most systems. * On my system (linux 2.4.18 with glibc 2.2.5) i can use 8-byte integers * (also called int64 or int8) * On my laptop (Windows 2000) i only could use numbers up to 4-byte (32 bit) * integers. * So you might want to test this first! *
/** * Connect to the database server, log in and open the database * * Don't call this method directly. Use DB::connect() instead. * * @param array $dsn the data source name * @param bool $persistent should the connection be persistent? * * @return int DB_OK on success. A DB_Error object on failure. */ function connect($dsn, $persistent = false) { if (!PEAR::loadExtension('fbsql')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsn; if ($dsn['dbsyntax']) { $this->dbsyntax = $dsn['dbsyntax']; } $params = array($dsn['hostspec'] ? $dsn['hostspec'] : 'localhost', $dsn['username'] ? $dsn['username'] : null, $dsn['password'] ? $dsn['password'] : null); $connect_function = $persistent ? 'fbsql_pconnect' : 'fbsql_connect'; $ini = ini_get('track_errors'); $php_errormsg = ''; if ($ini) { $this->connection = @call_user_func_array($connect_function, $params); } else { @ini_set('track_errors', 1); $this->connection = @call_user_func_array($connect_function, $params); @ini_set('track_errors', $ini); } if (!$this->connection) { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $php_errormsg); } if ($dsn['database']) { if (!@fbsql_select_db($dsn['database'], $this->connection)) { return $this->fbsqlRaiseError(); } } return DB_OK; }
/** * Creates a new Image_Transform object * * @param string $driver name of driver class to initialize. If no driver * is specified the factory will attempt to use 'Imagick' first * then 'GD' second, then 'Imlib' last * * @return object an Image_Transform object, or PEAR_Error on error * * @see PEAR::isError() * @see Image_Transform::setOption() */ static function &factory($driver = '') { if ($driver == '') { $extensions = array('imagick' => 'Imagick2', 'gd' => 'GD', 'imlib' => 'Imlib'); foreach ($extensions as $ext => $ext_driver) { if (PEAR::loadExtension($ext)) { $driver = $ext_driver; break; } } if (!$driver) { return PEAR::raiseError('No image library specified and none can be found. You must specify driver in factory() call.', IMAGE_TRANSFORM_ERROR_ARGUMENT); } } @(include_once 'Image/Transform/Driver/' . basename($driver) . '.php'); $classname = "Image_Transform_Driver_{$driver}"; if (!class_exists($classname)) { return PEAR::raiseError('Image library not supported... aborting.', IMAGE_TRANSFORM_ERROR_UNSUPPORTED); } $obj = new $classname(); // Check startup error if ($error = $obj->isError()) { $obj = $error; } return $obj; }
/** * Archive_Zip Class constructor. This flavour of the constructor only * declare a new Archive_Zip object, identifying it by the name of the * zip file. * * @param string $p_zipname The name of the zip archive to create * @access public */ function Archive_Zip($p_zipname) { // ----- Check the zlib if (!extension_loaded('zlib')) { PEAR::loadExtension('zlib'); } if (!extension_loaded('zlib')) { die("The extension 'zlib' couldn't be found.\n" . "Please make sure your version of PHP was built " . "with 'zlib' support.\n"); return false; } // ----- Set the attributes $this->_zipname = $p_zipname; $this->_zip_fd = 0; return; }
/** * Connect to the database server, log in and open the database * * Don't call this method directly. Use DB::connect() instead. * * PEAR DB's sybase driver supports the following extra DSN options: * + appname The application name to use on this connection. * Available since PEAR DB 1.7.0. * + charset The character set to use on this connection. * Available since PEAR DB 1.7.0. * * @param array $dsn the data source name * @param bool $persistent should the connection be persistent? * * @return int DB_OK on success. A DB_Error object on failure. */ function connect($dsn, $persistent = false) { if (!PEAR::loadExtension('sybase') && !PEAR::loadExtension('sybase_ct')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsn; if ($dsn['dbsyntax']) { $this->dbsyntax = $dsn['dbsyntax']; } $dsn['hostspec'] = $dsn['hostspec'] ? $dsn['hostspec'] : 'localhost'; $dsn['password'] = !empty($dsn['password']) ? $dsn['password'] : false; $dsn['charset'] = isset($dsn['charset']) ? $dsn['charset'] : false; $dsn['appname'] = isset($dsn['appname']) ? $dsn['appname'] : false; $connect_function = $persistent ? 'sybase_pconnect' : 'sybase_connect'; if ($dsn['username']) { $this->connection = @$connect_function($dsn['hostspec'], $dsn['username'], $dsn['password'], $dsn['charset'], $dsn['appname']); } else { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, 'The DSN did not contain a username.'); } if (!$this->connection) { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, @sybase_get_last_message()); } if ($dsn['database']) { if (!@sybase_select_db($dsn['database'], $this->connection)) { return $this->raiseError(DB_ERROR_NODBSELECTED, null, null, null, @sybase_get_last_message()); } $this->_db = $dsn['database']; } return DB_OK; }
/** * Connect and bind to LDAP server with either anonymous or authenticated bind depending on dsn info * * @param array $dsninfo dsn info as passed by DB::connect() * @param boolean $persistent kept for interface compatibility * @return DB_OK if successfully connected. A DB error code is returned on failure. */ function connect($dsninfo, $persistent = false) { if (!PEAR::loadExtension('ldap')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; $user = $dsninfo['username']; $pw = $dsninfo['password']; $host = $dsninfo['hostspec']; $port = $dsninfo['port']; $this->base = $dsninfo['database']; $this->d_base = $this->base; $version = $dsninfo['protocol']; if (empty($host)) { return $this->raiseError("no host specified {$host}"); } // else ... if (isset($port)) { $conn = ldap_connect($host, $port); } else { $conn = ldap_connect($host); } if (!$conn) { return $this->raiseError(DB_ERROR_CONNECT_FAILED); } if (isset($version)) { ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, $version); } else { // Use 3 by default $res = ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3); // If 3 fails then we can try 2 if (!$res) { ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 2); } } if ($user && $pw) { $bind = @ldap_bind($conn, $user, $pw); } else { $bind = @ldap_bind($conn); } if (!$bind) { return $this->raiseError(DB_ERROR_BIND_FAILED); } $this->connection = $conn; return DB_OK; }
/** * Connect to the database * * @return true on success, MDB2 Error Object on failure */ function connect() { if (is_object($this->connection)) { if (count(array_diff($this->connected_dsn, $this->dsn)) == 0) { return MDB2_OK; } $this->connection = 0; } if (!PEAR::loadExtension($this->phptype)) { return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 'extension ' . $this->phptype . ' is not compiled into PHP', __FUNCTION__); } if ($this->options['ssl']) { $init = @mysqli_init(); @mysqli_ssl_set($init, empty($this->dsn['key']) ? null : $this->dsn['key'], empty($this->dsn['cert']) ? null : $this->dsn['cert'], empty($this->dsn['ca']) ? null : $this->dsn['ca'], empty($this->dsn['capath']) ? null : $this->dsn['capath'], empty($this->dsn['cipher']) ? null : $this->dsn['cipher']); if ($connection = @mysqli_real_connect($init, $this->dsn['hostspec'], $this->dsn['username'], $this->dsn['password'], $this->database_name, $this->dsn['port'], $this->dsn['socket'])) { $connection = $init; } } else { $connection = @mysqli_connect($this->dsn['hostspec'], $this->dsn['username'], $this->dsn['password'], $this->database_name, $this->dsn['port'], $this->dsn['socket']); } if (!$connection) { if (($err = @mysqli_connect_error()) != '') { return $this->raiseError(null, null, null, $err, __FUNCTION__); } else { return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null, 'unable to establish a connection', __FUNCTION__); } } if (!empty($this->dsn['charset'])) { $result = $this->setCharset($this->dsn['charset'], $connection); if (PEAR::isError($result)) { return $result; } } $this->connection = $connection; $this->connected_dsn = $this->dsn; $this->connected_database_name = $this->database_name; $this->dbsyntax = $this->dsn['dbsyntax'] ? $this->dsn['dbsyntax'] : $this->phptype; $this->supported['transactions'] = $this->options['use_transactions']; if ($this->options['default_table_type']) { switch (strtoupper($this->options['default_table_type'])) { case 'BLACKHOLE': case 'MEMORY': case 'ARCHIVE': case 'CSV': case 'HEAP': case 'ISAM': case 'MERGE': case 'MRG_ISAM': case 'ISAM': case 'MRG_MYISAM': case 'MYISAM': $this->supported['transactions'] = false; $this->warnings[] = $this->options['default_table_type'] . ' is not a supported default table type'; break; } } $this->_getServerCapabilities(); return MDB2_OK; }
/** * Connect to the database server, log in and open the database * * Don't call this method directly. Use DB::connect() instead. * * If PHP is at version 5.0.0 or greater: * + Generally, oci_connect() or oci_pconnect() are used. * + But if the new_link DSN option is set to true, oci_new_connect() * is used. * * When using PHP version 4.x, OCILogon() or OCIPLogon() are used. * * PEAR DB's oci8 driver supports the following extra DSN options: * + charset The character set to be used on the connection. * Only used if PHP is at version 5.0.0 or greater * and the Oracle server is at 9.2 or greater. * Available since PEAR DB 1.7.0. * + new_link If set to true, causes subsequent calls to * connect() to return a new connection link * instead of the existing one. WARNING: this is * not portable to other DBMS's. * Available since PEAR DB 1.7.0. * * @param array $dsn the data source name * @param bool $persistent should the connection be persistent? * * @return int DB_OK on success. A DB_Error object on failure. */ function connect($dsn, $persistent = false) { if (!PEAR::loadExtension('oci8')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsn; if ($dsn['dbsyntax']) { $this->dbsyntax = $dsn['dbsyntax']; } // Backwards compatibility with DB < 1.7.0 if (empty($dsn['database']) && !empty($dsn['hostspec'])) { $db = $dsn['hostspec']; } else { $db = $dsn['database']; } if (function_exists('oci_connect')) { if (isset($dsn['new_link']) && ($dsn['new_link'] == 'true' || $dsn['new_link'] === true)) { $connect_function = 'oci_new_connect'; } else { $connect_function = $persistent ? 'oci_pconnect' : 'oci_connect'; } if (isset($this->dsn['port']) && $this->dsn['port']) { $db = '//' . $db . ':' . $this->dsn['port']; } $char = empty($dsn['charset']) ? null : $dsn['charset']; $this->connection = @$connect_function($dsn['username'], $dsn['password'], $db, $char); $error = OCIError(); if (!empty($error) && $error['code'] == 12541) { // Couldn't find TNS listener. Try direct connection. $this->connection = @$connect_function($dsn['username'], $dsn['password'], null, $char); } } else { $connect_function = $persistent ? 'OCIPLogon' : 'OCILogon'; if ($db) { $this->connection = @$connect_function($dsn['username'], $dsn['password'], $db); } elseif ($dsn['username'] || $dsn['password']) { $this->connection = @$connect_function($dsn['username'], $dsn['password']); } } if (!$this->connection) { $error = OCIError(); $error = is_array($error) ? $error['message'] : null; return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $error); } return DB_OK; }
/** * Connect to the database * * @return true on success, MDB2 Error Object on failure */ function connect() { if (is_resource($this->connection)) { if (count(array_diff($this->connected_dsn, $this->dsn)) == 0 && $this->opened_persistent == $this->options['persistent']) { return MDB2_OK; } $this->disconnect(false); } if (!PEAR::loadExtension($this->phptype)) { return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 'connect: extension ' . $this->phptype . ' is not compiled into PHP'); } $params = array(); if ($this->dsn['protocol'] && $this->dsn['protocol'] == 'unix') { $params[0] = ':' . $this->dsn['socket']; } else { $params[0] = $this->dsn['hostspec'] ? $this->dsn['hostspec'] : 'localhost'; if ($this->dsn['port']) { $params[0] .= ':' . $this->dsn['port']; } } $params[] = $this->dsn['username'] ? $this->dsn['username'] : null; $params[] = $this->dsn['password'] ? $this->dsn['password'] : null; if (!$this->options['persistent']) { if (isset($this->dsn['new_link']) && ($this->dsn['new_link'] == 'true' || $this->dsn['new_link'] === true)) { $params[] = true; } else { $params[] = false; } } if (version_compare(phpversion(), '4.3.0', '>=')) { $params[] = isset($this->dsn['client_flags']) ? $this->dsn['client_flags'] : null; } $connect_function = $this->options['persistent'] ? 'mysql_pconnect' : 'mysql_connect'; @ini_set('track_errors', true); $php_errormsg = ''; $connection = @call_user_func_array($connect_function, $params); @ini_restore('track_errors'); if (!$connection) { if (($err = @mysql_error()) != '') { return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null, $err); } else { return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null, $php_errormsg); } } $this->connection = $connection; $this->connected_dsn = $this->dsn; $this->connected_database_name = ''; $this->opened_persistent = $this->options['persistent']; $this->dbsyntax = $this->dsn['dbsyntax'] ? $this->dsn['dbsyntax'] : $this->phptype; $this->supported['transactions'] = false; if ($this->options['default_table_type']) { switch (strtoupper($this->options['default_table_type'])) { case 'BERKELEYDB': $this->options['default_table_type'] = 'BDB'; case 'BDB': case 'INNODB': case 'GEMINI': $this->supported['transactions'] = true; break; case 'HEAP': case 'ISAM': case 'MERGE': case 'MRG_MYISAM': case 'MYISAM': break; default: $this->warnings[] = $default_table_type . ' is not a supported default table type'; } } if ($this->options['use_transactions'] && !$this->supports('transactions')) { $this->warnings[] = $this->options['default_table_type'] . ' is not a transaction-safe default table type; switched to INNODB'; $this->options['default_table_type'] = 'INNODB'; $this->supported['transactions'] = true; } return MDB2_OK; }
/** * Connect to the database server, log in and open the database * * Don't call this method directly. Use DB::connect() instead. * * PEAR DB's mysqli driver supports the following extra DSN options: * + When the 'ssl' $option passed to DB::connect() is true: * + key The path to the key file. * + cert The path to the certificate file. * + ca The path to the certificate authority file. * + capath The path to a directory that contains trusted SSL * CA certificates in pem format. * + cipher The list of allowable ciphers for SSL encryption. * * Example of how to connect using SSL: * <code> * require_once 'DB.php'; * * $dsn = array( * 'phptype' => 'mysqli', * 'username' => 'someuser', * 'password' => 'apasswd', * 'hostspec' => 'localhost', * 'database' => 'thedb', * 'key' => 'client-key.pem', * 'cert' => 'client-cert.pem', * 'ca' => 'cacert.pem', * 'capath' => '/path/to/ca/dir', * 'cipher' => 'AES', * ); * * $options = array( * 'ssl' => true, * ); * * $db =& DB::connect($dsn, $options); * if (PEAR::isError($db)) { * die($db->getMessage()); * } * </code> * * @param array $dsn the data source name * @param bool $persistent should the connection be persistent? * * @return int DB_OK on success. A DB_Error object on failure. */ function connect($dsn, $persistent = false) { if (!PEAR::loadExtension('mysqli')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsn; if ($dsn['dbsyntax']) { $this->dbsyntax = $dsn['dbsyntax']; } $ini = ini_get('track_errors'); ini_set('track_errors', 1); $php_errormsg = ''; if ($this->getOption('ssl') === true) { $init = mysqli_init(); mysqli_ssl_set($init, empty($dsn['key']) ? null : $dsn['key'], empty($dsn['cert']) ? null : $dsn['cert'], empty($dsn['ca']) ? null : $dsn['ca'], empty($dsn['capath']) ? null : $dsn['capath'], empty($dsn['cipher']) ? null : $dsn['cipher']); if ($this->connection = @mysqli_real_connect($init, $dsn['hostspec'], $dsn['username'], $dsn['password'], $dsn['database'], $dsn['port'], $dsn['socket'])) { $this->connection = $init; } } else { $this->connection = @mysqli_connect($dsn['hostspec'], $dsn['username'], $dsn['password'], $dsn['database'], $dsn['port'], $dsn['socket']); } ini_set('track_errors', $ini); if (!$this->connection) { if (($err = @mysqli_connect_error()) != '') { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $err); } else { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $php_errormsg); } } if ($dsn['database']) { $this->_db = $dsn['database']; } return DB_OK; }
/** * Connect to the database server, log in and open the database * * Don't call this method directly. Use DB::connect() instead. * * PEAR DB's mysql driver supports the following extra DSN options: * + new_link If set to true, causes subsequent calls to connect() * to return a new connection link instead of the * existing one. WARNING: this is not portable to * other DBMS's. Available since PEAR DB 1.7.0. * + client_flags Any combination of MYSQL_CLIENT_* constants. * Only used if PHP is at version 4.3.0 or greater. * Available since PEAR DB 1.7.0. * * @param array $dsn the data source name * @param bool $persistent should the connection be persistent? * * @return int DB_OK on success. A DB_Error object on failure. */ function connect($dsn, $persistent = false) { if (!PEAR::loadExtension('mysql')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsn; if ($dsn['dbsyntax']) { $this->dbsyntax = $dsn['dbsyntax']; } $params = array(); if ($dsn['protocol'] && $dsn['protocol'] == 'unix') { $params[0] = ':' . $dsn['socket']; } else { $params[0] = $dsn['hostspec'] ? $dsn['hostspec'] : 'localhost'; if ($dsn['port']) { $params[0] .= ':' . $dsn['port']; } } $params[] = $dsn['username'] ? $dsn['username'] : null; $params[] = $dsn['password'] ? $dsn['password'] : null; if (!$persistent) { if (isset($dsn['new_link']) && ($dsn['new_link'] == 'true' || $dsn['new_link'] === true)) { $params[] = true; } else { $params[] = false; } } if (version_compare(phpversion(), '4.3.0', '>=')) { $params[] = isset($dsn['client_flags']) ? $dsn['client_flags'] : null; } $connect_function = $persistent ? 'mysql_pconnect' : 'mysql_connect'; $ini = ini_get('track_errors'); $php_errormsg = ''; if ($ini) { $this->connection = @call_user_func_array($connect_function, $params); } else { ini_set('track_errors', 1); $this->connection = @call_user_func_array($connect_function, $params); ini_set('track_errors', $ini); } if (!$this->connection) { if (($err = @mysql_error()) != '') { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $err); } else { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $php_errormsg); } } if ($dsn['database']) { if (!@mysql_select_db($dsn['database'], $this->connection)) { return $this->mysqlRaiseError(); } $this->_db = $dsn['database']; } return DB_OK; }
/** * Creates a cURL resource. If curl_init() doesn't exist or we could not * create a resource it will error out. * * @author Joe Stump <*****@*****.**> * @return boolean TRUE on success, PEAR_Error on failure */ function create() { if (!PEAR::loadExtension('curl')) { return PEAR::raiseError('CURL extension is not available'); } if (!function_exists('curl_init')) { return PEAR::raiseError('Function curl_init() not found'); } $this->_ch = curl_init(); if (!is_resource($this->_ch)) { return PEAR::raiseError('Could not initialize cURL handler'); } return true; }
/** * Connect to the database server, log in and open the database * * Don't call this method directly. Use DB::connect() instead. * * PEAR DB's pgsql driver supports the following extra DSN options: * + connect_timeout How many seconds to wait for a connection to * be established. Available since PEAR DB 1.7.0. * + new_link If set to true, causes subsequent calls to * connect() to return a new connection link * instead of the existing one. WARNING: this is * not portable to other DBMS's. Available only * if PHP is >= 4.3.0 and PEAR DB is >= 1.7.0. * + options Command line options to be sent to the server. * Available since PEAR DB 1.6.4. * + service Specifies a service name in pg_service.conf that * holds additional connection parameters. * Available since PEAR DB 1.7.0. * + sslmode How should SSL be used when connecting? Values: * disable, allow, prefer or require. * Available since PEAR DB 1.7.0. * + tty This was used to specify where to send server * debug output. Available since PEAR DB 1.6.4. * * Example of connecting to a new link via a socket: * <code> * require_once 'DB.php'; * * $dsn = 'pgsql://*****:*****@unix(/tmp)/dbname?new_link=true'; * $options = array( * 'portability' => DB_PORTABILITY_ALL, * ); * * $db =& DB::connect($dsn, $options); * if (PEAR::isError($db)) { * die($db->getMessage()); * } * </code> * * @param array $dsn the data source name * @param bool $persistent should the connection be persistent? * * @return int DB_OK on success. A DB_Error object on failure. * * @link http://www.postgresql.org/docs/current/static/libpq.html#LIBPQ-CONNECT */ function connect($dsn, $persistent = false) { if (!PEAR::loadExtension('pgsql')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsn; if ($dsn['dbsyntax']) { $this->dbsyntax = $dsn['dbsyntax']; } $protocol = $dsn['protocol'] ? $dsn['protocol'] : 'tcp'; $params = array(''); if ($protocol == 'tcp') { if ($dsn['hostspec']) { $params[0] .= 'host=' . $dsn['hostspec']; } if ($dsn['port']) { $params[0] .= ' port=' . $dsn['port']; } } elseif ($protocol == 'unix') { // Allow for pg socket in non-standard locations. if ($dsn['socket']) { $params[0] .= 'host=' . $dsn['socket']; } if ($dsn['port']) { $params[0] .= ' port=' . $dsn['port']; } } if ($dsn['database']) { $params[0] .= ' dbname=\'' . addslashes($dsn['database']) . '\''; } if ($dsn['username']) { $params[0] .= ' user=\'' . addslashes($dsn['username']) . '\''; } if ($dsn['password']) { $params[0] .= ' password=\'' . addslashes($dsn['password']) . '\''; } if (!empty($dsn['options'])) { $params[0] .= ' options=' . $dsn['options']; } if (!empty($dsn['tty'])) { $params[0] .= ' tty=' . $dsn['tty']; } if (!empty($dsn['connect_timeout'])) { $params[0] .= ' connect_timeout=' . $dsn['connect_timeout']; } if (!empty($dsn['sslmode'])) { $params[0] .= ' sslmode=' . $dsn['sslmode']; } if (!empty($dsn['service'])) { $params[0] .= ' service=' . $dsn['service']; } if (isset($dsn['new_link']) && ($dsn['new_link'] == 'true' || $dsn['new_link'] === true)) { if (version_compare(phpversion(), '4.3.0', '>=')) { $params[] = PGSQL_CONNECT_FORCE_NEW; } } $connect_function = $persistent ? 'pg_pconnect' : 'pg_connect'; $ini = ini_get('track_errors'); $php_errormsg = ''; if ($ini) { $this->connection = @call_user_func_array($connect_function, $params); } else { @ini_set('track_errors', 1); $this->connection = @call_user_func_array($connect_function, $params); @ini_set('track_errors', $ini); } if (!$this->connection) { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $php_errormsg); } return DB_OK; }
* PHP versions 4 and 5 * * @category Web Services * @package XML_RPC * @author Edd Dumbill <*****@*****.**> * @author Stig Bakken <*****@*****.**> * @author Martin Jansen <*****@*****.**> * @author Daniel Convissor <*****@*****.**> * @copyright 1999-2001 Edd Dumbill, 2001-2010 The PHP Group * @license http://www.php.net/license/3_01.txt PHP License * @version SVN: $Id: RPC.php 293238 2010-01-08 03:21:06Z danielc $ * @link http://pear.php.net/package/XML_RPC */ if (!function_exists('xml_parser_create')) { include_once 'PEAR.php'; PEAR::loadExtension('xml'); } /**#@+ * Error constants */ /** * Parameter values don't match parameter types */ define('XML_RPC_ERROR_INVALID_TYPE', 101); /** * Parameter declared to be numeric but the values are not */ define('XML_RPC_ERROR_NON_NUMERIC_FOUND', 102); /** * Communication error */
/** * Archive_Tar Class constructor. This flavour of the constructor only * declare a new Archive_Tar object, identifying it by the name of the * tar file. * If the compress argument is set the tar will be read or created as a * gzip or bz2 compressed TAR file. * * @param string $p_tarname The name of the tar archive to create * @param string $p_compress can be null, 'gz' or 'bz2'. This * parameter indicates if gzip or bz2 compression * is required. For compatibility reason the * boolean value 'true' means 'gz'. * @access public */ function Archive_Tar($p_tarname, $p_compress = NULL) { $this->PEAR(); $this->_compress = false; $this->_compress_type = 'none'; if ($p_compress === null || $p_compress == '') { if (@file_exists($p_tarname)) { if ($fp = @fopen($p_tarname, "rb")) { // look for gzip magic cookie $data = fread($fp, 2); fclose($fp); if ($data == "‹") { $this->_compress = true; $this->_compress_type = 'gz'; // No sure it's enought for a magic code .... } elseif ($data == "BZ") { $this->_compress = true; $this->_compress_type = 'bz2'; } } } else { // probably a remote file or some file accessible // through a stream interface if (substr($p_tarname, -2) == 'gz') { $this->_compress = true; $this->_compress_type = 'gz'; } elseif (substr($p_tarname, -3) == 'bz2' || substr($p_tarname, -2) == 'bz') { $this->_compress = true; $this->_compress_type = 'bz2'; } } } else { if ($p_compress === true || $p_compress == 'gz') { $this->_compress = true; $this->_compress_type = 'gz'; } else { if ($p_compress == 'bz2') { $this->_compress = true; $this->_compress_type = 'bz2'; } else { die("Unsupported compression type '{$p_compress}'\n" . "Supported types are 'gz' and 'bz2'.\n"); return false; } } } $this->_tarname = $p_tarname; if ($this->_compress) { // assert zlib or bz2 extension support if ($this->_compress_type == 'gz') { $extname = 'zlib'; } else { if ($this->_compress_type == 'bz2') { $extname = 'bz2'; } } if (!extension_loaded($extname)) { PEAR::loadExtension($extname); } if (!extension_loaded($extname)) { die("The extension '{$extname}' couldn't be found.\n" . "Please make sure your version of PHP was built " . "with '{$extname}' support.\n"); return false; } } }
/** * Connect to the database server, log in and open the database * * Don't call this method directly. Use DB::connect() instead. * * @param array $dsn the data source name * @param bool $persistent should the connection be persistent? * * @return int DB_OK on success. A DB_Error object on failure. */ function connect($dsn, $persistent = false) { if (!PEAR::loadExtension('informix') && !PEAR::loadExtension('Informix')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsn; if ($dsn['dbsyntax']) { $this->dbsyntax = $dsn['dbsyntax']; } $dbhost = $dsn['hostspec'] ? '@' . $dsn['hostspec'] : ''; $dbname = $dsn['database'] ? $dsn['database'] . $dbhost : ''; $user = $dsn['username'] ? $dsn['username'] : ''; $pw = $dsn['password'] ? $dsn['password'] : ''; $connect_function = $persistent ? 'ifx_pconnect' : 'ifx_connect'; $this->connection = @$connect_function($dbname, $user, $pw); if (!is_resource($this->connection)) { return $this->ifxRaiseError(DB_ERROR_CONNECT_FAILED); } return DB_OK; }
/** * Crypt_Blowfish object factory * * This is the recommended method to create a Crypt_Blowfish instance. * * When using CRYPT_BLOWFISH_AUTO, you can force the package to ignore * the MCrypt extension, by defining CRYPT_BLOWFISH_NOMCRYPT. * * @param string $mode operating mode 'ecb' or 'cbc' (case insensitive) * @param string $key * @param string $iv initialization vector (must be provided for CBC mode) * @param integer $engine one of CRYPT_BLOWFISH_AUTO, CRYPT_BLOWFISH_PHP * or CRYPT_BLOWFISH_MCRYPT * @return object Crypt_Blowfish object or PEAR_Error object on error * @access public * @static * @since 1.1.0 */ function &factory($mode = 'ecb', $key = null, $iv = null, $engine = CRYPT_BLOWFISH_AUTO) { switch ($engine) { case CRYPT_BLOWFISH_AUTO: if (!defined('CRYPT_BLOWFISH_NOMCRYPT') && extension_loaded('mcrypt')) { $engine = CRYPT_BLOWFISH_MCRYPT; } else { $engine = CRYPT_BLOWFISH_PHP; } break; case CRYPT_BLOWFISH_MCRYPT: if (!PEAR::loadExtension('mcrypt')) { return PEAR::raiseError('MCrypt extension is not available.'); } break; } switch ($engine) { case CRYPT_BLOWFISH_PHP: $mode = strtoupper($mode); $class = 'Crypt_Blowfish_' . $mode; include_once 'Crypt/Blowfish/' . $mode . '.php'; $crypt = new $class(null); break; case CRYPT_BLOWFISH_MCRYPT: include_once 'Crypt/Blowfish/MCrypt.php'; $crypt = new Crypt_Blowfish_MCrypt(null, $mode); break; } if (!is_null($key) || !is_null($iv)) { $result = $crypt->setKey($key, $iv); if (PEAR::isError($result)) { return $result; } } return $crypt; }
/** * Connect to the database server, log in and open the database * * Don't call this method directly. Use DB::connect() instead. * * PEAR DB's ibase driver supports the following extra DSN options: * + buffers The number of database buffers to allocate for the * server-side cache. * + charset The default character set for a database. * + dialect The default SQL dialect for any statement * executed within a connection. Defaults to the * highest one supported by client libraries. * Functional only with InterBase 6 and up. * + role Functional only with InterBase 5 and up. * * @param array $dsn the data source name * @param bool $persistent should the connection be persistent? * * @return int DB_OK on success. A DB_Error object on failure. */ function connect($dsn, $persistent = false) { if (!PEAR::loadExtension('interbase')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsn; if ($dsn['dbsyntax']) { $this->dbsyntax = $dsn['dbsyntax']; } if ($this->dbsyntax == 'firebird') { $this->features['limit'] = 'alter'; } $params = array($dsn['hostspec'] ? $dsn['hostspec'] . ':' . $dsn['database'] : $dsn['database'], $dsn['username'] ? $dsn['username'] : null, $dsn['password'] ? $dsn['password'] : null, isset($dsn['charset']) ? $dsn['charset'] : null, isset($dsn['buffers']) ? $dsn['buffers'] : null, isset($dsn['dialect']) ? $dsn['dialect'] : null, isset($dsn['role']) ? $dsn['role'] : null); $connect_function = $persistent ? 'ibase_pconnect' : 'ibase_connect'; $this->connection = @call_user_func_array($connect_function, $params); if (!$this->connection) { return $this->ibaseRaiseError(DB_ERROR_CONNECT_FAILED); } return DB_OK; }
/** * Connect to the database server, log in and open the database * * Don't call this method directly. Use DB::connect() instead. * * @param array $dsn the data source name * @param bool $persistent should the connection be persistent? * * @return int DB_OK on success. A DB_Error object on failure. */ function connect($dsn, $persistent = false) { if (!PEAR::loadExtension('mssql') && !PEAR::loadExtension('sybase') && !PEAR::loadExtension('sybase_ct')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsn; if ($dsn['dbsyntax']) { $this->dbsyntax = $dsn['dbsyntax']; } $params = array($dsn['hostspec'] ? $dsn['hostspec'] : 'localhost', $dsn['username'] ? $dsn['username'] : null, $dsn['password'] ? $dsn['password'] : null); if ($dsn['port']) { $params[0] .= (substr(PHP_OS, 0, 3) == 'WIN' ? ',' : ':') . $dsn['port']; } $connect_function = $persistent ? 'mssql_pconnect' : 'mssql_connect'; $this->connection = @call_user_func_array($connect_function, $params); if (!$this->connection) { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, @mssql_get_last_message()); } if ($dsn['database']) { if (!@mssql_select_db($dsn['database'], $this->connection)) { return $this->raiseError(DB_ERROR_NODBSELECTED, null, null, null, @mssql_get_last_message()); } $this->_db = $dsn['database']; } return DB_OK; }
/** * Connect to the database server, log in and open the database * * Don't call this method directly. Use DB::connect() instead. * * Example of how to connect: * <code> * require_once 'DB.php'; * * // $dsn = 'msql://hostname/dbname'; // use a TCP connection * $dsn = 'msql:///dbname'; // use a socket * $options = array( * 'portability' => DB_PORTABILITY_ALL, * ); * * $db =& DB::connect($dsn, $options); * if (PEAR::isError($db)) { * die($db->getMessage()); * } * </code> * * @param array $dsn the data source name * @param bool $persistent should the connection be persistent? * * @return int DB_OK on success. A DB_Error object on failure. */ function connect($dsn, $persistent = false) { if (!PEAR::loadExtension('msql')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsn; if ($dsn['dbsyntax']) { $this->dbsyntax = $dsn['dbsyntax']; } $params = array(); if ($dsn['hostspec']) { $params[] = $dsn['port'] ? $dsn['hostspec'] . ',' . $dsn['port'] : $dsn['hostspec']; } $connect_function = $persistent ? 'msql_pconnect' : 'msql_connect'; $ini = ini_get('track_errors'); $php_errormsg = ''; if ($ini) { $this->connection = @call_user_func_array($connect_function, $params); } else { ini_set('track_errors', 1); $this->connection = @call_user_func_array($connect_function, $params); ini_set('track_errors', $ini); } if (!$this->connection) { if (($err = @msql_error()) != '') { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $err); } else { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $php_errormsg); } } if (!@msql_select_db($dsn['database'], $this->connection)) { return $this->msqlRaiseError(); } return DB_OK; }
/** * Connect to the database and create it if it doesn't exist * * Don't call this method directly. Use DB::connect() instead. * * PEAR DB's dbase driver supports the following extra DSN options: * + mode An integer specifying the read/write mode to use * (0 = read only, 1 = write only, 2 = read/write). * Available since PEAR DB 1.7.0. * + fields An array of arrays that PHP's dbase_create() function needs * to create a new database. This information is used if the * dBase file specified in the "database" segment of the DSN * does not exist. For more info, see the PHP manual's * {@link http://php.net/dbase_create dbase_create()} page. * Available since PEAR DB 1.7.0. * * Example of how to connect and establish a new dBase file if necessary: * <code> * require_once 'DB.php'; * * $dsn = array( * 'phptype' => 'dbase', * 'database' => '/path/and/name/of/dbase/file', * 'mode' => 2, * 'fields' => array( * array('a', 'N', 5, 0), * array('b', 'C', 40), * array('c', 'C', 255), * array('d', 'C', 20), * ), * ); * $options = array( * 'debug' => 2, * 'portability' => DB_PORTABILITY_ALL, * ); * * $db = DB::connect($dsn, $options); * if (PEAR::isError($db)) { * die($db->getMessage()); * } * </code> * * @param array $dsn the data source name * @param bool $persistent should the connection be persistent? * * @return int DB_OK on success. A DB_Error object on failure. */ function connect($dsn, $persistent = false) { if (!PEAR::loadExtension('dbase')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsn; if ($dsn['dbsyntax']) { $this->dbsyntax = $dsn['dbsyntax']; } /* * Turn track_errors on for entire script since $php_errormsg * is the only way to find errors from the dbase extension. */ @ini_set('track_errors', 1); $php_errormsg = ''; if (!file_exists($dsn['database'])) { $this->dsn['mode'] = 2; if (empty($dsn['fields']) || !is_array($dsn['fields'])) { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, 'the dbase file does not exist and ' . 'it could not be created because ' . 'the "fields" element of the DSN ' . 'is not properly set'); } $this->connection = @dbase_create($dsn['database'], $dsn['fields']); if (!$this->connection) { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, 'the dbase file does not exist and ' . 'the attempt to create it failed: ' . $php_errormsg); } } else { if (!isset($this->dsn['mode'])) { $this->dsn['mode'] = 0; } $this->connection = @dbase_open($dsn['database'], $this->dsn['mode']); if (!$this->connection) { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $php_errormsg); } } return DB_OK; }
/** * Connect to the database * * @return true on success, MDB2 Error Object on failure */ function connect() { if (is_resource($this->connection)) { if (count(array_diff($this->connected_dsn, $this->dsn)) == 0 && $this->opened_persistent == $this->options['persistent'] && $this->connected_database_name == $this->database_name) { return MDB2_OK; } $this->disconnect(false); } if (!PEAR::loadExtension($this->phptype)) { return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 'extension ' . $this->phptype . ' is not compiled into PHP', __FUNCTION__); } $params = array(); if ($this->dsn['protocol'] && $this->dsn['protocol'] == 'unix') { $params[0] = ':' . $this->dsn['socket']; } else { $params[0] = $this->dsn['hostspec'] ? $this->dsn['hostspec'] : 'localhost'; if ($this->dsn['port']) { $params[0] .= ':' . $this->dsn['port']; } } $params[] = $this->dsn['username'] ? $this->dsn['username'] : null; $params[] = $this->dsn['password'] ? $this->dsn['password'] : null; if (!$this->options['persistent']) { if (isset($this->dsn['new_link']) && ($this->dsn['new_link'] == 'true' || $this->dsn['new_link'] === true)) { // $params[] = true; } else { // $params[] = false; } } if (version_compare(phpversion(), '4.3.0', '>=')) { // $params[] = isset($this->dsn['client_flags'])? $this->dsn['client_flags'] : null; } $connect_function = $this->options['persistent'] ? 'mysql_pconnect' : 'mysql_connect'; //print_r($params); //echo $connect_function; $connection = @call_user_func_array($connect_function, $params); if (!$connection) { //echo "No conecta"; if (($err = @mysql_error()) != '') { return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null, $err, __FUNCTION__); } else { return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null, 'unable to establish a connection', __FUNCTION__); } } else { //echo "si conecta"; } if (!empty($this->dsn['charset'])) { $result = $this->setCharset($this->dsn['charset'], $connection); if (PEAR::isError($result)) { return $result; } } //echo "con:".$connection; $this->connection = $connection; $this->connected_dsn = $this->dsn; $this->connected_database_name = ''; $this->opened_persistent = $this->options['persistent']; $this->dbsyntax = $this->dsn['dbsyntax'] ? $this->dsn['dbsyntax'] : $this->phptype; if ($this->database_name) { // echo "BDexiste"; if ($this->database_name != $this->connected_database_name) { if (!@mysql_select_db($this->database_name, $connection)) { //echo "No puede seleccionar:".$this->database_name; $err = $this->raiseError(null, null, null, 'Could not select the database: ' . $this->database_name, __FUNCTION__); return $err; } $this->connected_database_name = $this->database_name; //echo "BD:".$this->connected_database_name; } } $this->supported['transactions'] = $this->options['use_transactions']; if ($this->options['default_table_type']) { switch (strtoupper($this->options['default_table_type'])) { case 'BLACKHOLE': case 'MEMORY': case 'ARCHIVE': case 'CSV': case 'HEAP': case 'ISAM': case 'MERGE': case 'MRG_ISAM': case 'ISAM': case 'MRG_MYISAM': case 'MYISAM': $this->supported['transactions'] = false; $this->warnings[] = $this->options['default_table_type'] . ' is not a supported default table type'; break; } } $this->_getServerCapabilities(); return MDB2_OK; }