function run($answers, $phase) { switch ($phase) { case 'askdb': if ($answers['yesno'] != 'y') { $this->_ui->skipParamgroup('init'); } return true; break; case 'init': PEAR::pushErrorHandling(PEAR_ERROR_RETURN); if (PEAR::isError($err = MDB2::loadFile('Driver' . DIRECTORY_SEPARATOR . $answers['driver']))) { PEAR::popErrorHandling(); $this->_ui->outputData('ERROR: Unknown MDB2 driver "' . $answers['driver'] . '": ' . $err->getUserInfo() . '. Be sure you have installed ' . 'MDB2_Driver_' . $answers['driver']); return false; } PEAR::popErrorHandling(); if ($answers['driver'] !== 'mysqli') { $this->_ui->outputData('pearweb only supports mysqli, ' . 'not ' . $answers['driver']); return false; } return $this->initializeDatabase($answers); break; case 'askhttpd': if ($answers['yesno'] != 'y') { $this->_ui->skipParamgroup('httpdconf'); } return true; break; case 'httpdconf': return $this->setupHttpdconf($answers); break; } return true; }
$stmt = $mdb2->prepare($query, array('text', 'date'), MDB2_PREPARE_MANIP); if (PEAR::isError($stmt)) { die($stmt->getMessage()); } // load Date helper class MDB2::loadFile('Date'); $stmt->execute(array('name' => 'hello', 'date' => MDB2_Date::mdbToday())); // get the last inserted id echo 'last insert id: '; var_dump($mdb2->lastInsertId($table, 'id')); $stmt->execute(array('name' => 'world', 'date' => '2005-11-11')); // get the last inserted id echo 'last insert id: '; var_dump($mdb2->lastInsertId($table, 'id')); // load Iterator implementations MDB2::loadFile('Iterator'); $query = 'SELECT * FROM ' . $table; // parameters: // 1) the query // 2) true means MDB2 tries to determine the result set type automatically // 3) true is the default and means that internally a MDB2_Result instance should be created // 4) 'MDB2_BufferedIterator' means the MDB2_Result should be wrapped inside an SeekableIterator $result = $mdb2->query($query, true, true, 'MDB2_BufferedIterator'); // iterate over the result set foreach ($result as $row) { echo 'output row:<br>'; var_dump($row); } // call drop table, since dropTable is not implemented in our instance // but inside the loaded Manager module __call() will find it there and // will redirect the call accordingly
/** * Tests that the MDB2::loadFile() method returns the expected * filename. */ function test_loadFile() { $filename = 'Extended'; $this->assertEquals('MDB2' . DIRECTORY_SEPARATOR . $filename . '.php', MDB2::loadFile($filename), 'loadFile'); }
// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA /** * MDB2 container for Authentication * * @package LiveUser * @category authentication */ /** * Require parent class definition and PEAR::MDB2 class. */ require_once 'LiveUser/Auth/Common.php'; require_once 'MDB2.php'; MDB2::loadFile('Date'); /** * Class LiveUser_Auth_Container_MDB2 * * Description: * This is a PEAR::MDB2 backend driver for the LiveUser class. * A PEAR::MDB2 connection object can be passed to the constructor to reuse an * existing connection. Alternatively, a DSN can be passed to open a new one. * * Requirements: * - File "LoginManager.php" (contains the parent class "LiveUser") * - Array of connection options or a PEAR::MDB2 connection object must be * passed to the constructor. * Example: array('dsn' => 'mysql://*****:*****@host/db_name', * 'connection => &$conn, # PEAR::MDB2 connection object * 'loginTimeout' => 0,
/** * Installs table(s)/data schema into database * * @access public * @param string $new_schema New schema file path/name * @param array $variables Schema variables * @param string $old_schema Old schema file path/name * @param string $init_data Schema is include initialization data * @param string $create If the database should be created * @return mixed True on success and Jaws_Error on failure */ function installSchema($new_schema, $variables = array(), $old_schema = false, $init_data = false, $create = true) { MDB2::loadFile('Schema'); $dsn = $this->_dsn; unset($dsn['database']); // If the database should be created $variables['create'] = (int) $create; // The database name $variables['database'] = $this->_dsn['database']; // Prefix of all the tables added $variables['table_prefix'] = $this->getPrefix(); // set default charset if (!isset($variables['charset'])) { $variables['charset'] = $this->getUnicodeCharset(); } $options = array('debug' => false, 'log_line_break' => '<br />', 'portability' => MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL ^ MDB2_PORTABILITY_FIX_CASE ^ MDB2_PORTABILITY_RTRIM, 'quote_identifier' => true, 'force_defaults' => false); switch ($this->_dsn['phptype']) { case 'ibase': $options['portability'] = $options['portability'] | MDB2_PORTABILITY_FIX_CASE; $options['database_path'] = empty($this->_db_path) ? JAWS_DATA : $this->_db_path; break; case 'oci8': $options['emulate_database'] = false; $options['portability'] = $options['portability'] | MDB2_PORTABILITY_FIX_CASE; break; case 'sqlite': $options['database_path'] = empty($this->_db_path) ? JAWS_DATA : $this->_db_path; break; case 'mssql': $options['multibyte_text_field_type'] = $this->Is_FreeTDS_MSSQL_Driver(); break; } if ($this->_is_dba) { $options['DBA_username'] = $this->_dsn['username']; $options['DBA_password'] = $this->_dsn['password']; } if (!isset($this->schema)) { $this->schema =& MDB2_Schema::factory($this->dbc, $options); if (MDB2::isError($this->schema)) { return $this->schema; } } $method = $init_data === true ? 'writeInitialization' : 'updateDatabase'; $result = $this->schema->{$method}($new_schema, $old_schema, $variables); if (MDB2::isError($result)) { $this->schema->disconnect(); unset($this->schema); $GLOBALS['log']->Log(JAWS_ERROR_ERROR, $result->getUserInfo(), 2); return new Jaws_Error($result->getMessage(), $result->getCode(), JAWS_ERROR_ERROR, 1); } return $result; }
<html> <body> '; if (isset($_REQUEST['submit']) && $_REQUEST['file'] != '') { // BC hack to define PATH_SEPARATOR for version of PHP prior 4.3 if (!defined('PATH_SEPARATOR')) { if (defined('DIRECTORY_SEPARATOR') && DIRECTORY_SEPARATOR == "\\") { define('PATH_SEPARATOR', ';'); } else { define('PATH_SEPARATOR', ':'); } } ini_set('include_path', '../../' . PATH_SEPARATOR . ini_get('include_path')); require_once 'MDB2.php'; @(include_once 'Var_Dump.php'); MDB2::loadFile('Tools/Manager'); $dsn = $_REQUEST['type'] . '://' . $_REQUEST['user'] . ':' . $_REQUEST['pass'] . '@' . $_REQUEST['host'] . '/' . $_REQUEST['name']; $manager =& new MDB2_Tools_Manager(); $err = $manager->connect($dsn, array('debug' => true, 'log_line_break' => '<br>')); if (MDB2::isError($err)) { $error = $err->getMessage(); } else { if ($_REQUEST['action']) { set_time_limit(0); } if ($_REQUEST['action'] == 'dump') { switch ($_REQUEST['dump']) { case 'structure': $dump_what = MDB2_MANAGER_DUMP_STRUCTURE; break; case 'content':
// $Id: peardb_wrapper_example.php,v 1.2 2004/04/25 10:05:30 lsmith Exp $ // // MDB2 test script for the PEAR DB Wrapper. // // BC hack to define PATH_SEPARATOR for version of PHP prior 4.3 if (!defined('PATH_SEPARATOR')) { if (defined('DIRECTORY_SEPARATOR') && DIRECTORY_SEPARATOR == "\\") { define('PATH_SEPARATOR', ';'); } else { define('PATH_SEPARATOR', ':'); } } ini_set('include_path', '../..' . PATH_SEPARATOR . ini_get('include_path')); require_once 'MDB2.php'; MDB2::loadFile('Wrapper/peardb'); require_once 'Var_Dump.php'; PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handle_pear_error'); function handle_pear_error($error_obj) { print '<pre><b>PEAR-Error</b><br />'; echo $error_obj->getMessage() . ': ' . $error_obj->getUserinfo(); print '</pre>'; } // just for kicks you can mess up this part to see some pear error handling $user = '******'; $pass = '******'; //$pass = ''; $host = 'localhost'; $db_name = 'metapear_test_db'; // Data Source Name: This is the universal connection string
/** * Create a handler object of a specified class with functions to * retrieve data from a large object data stream. * * @param array $arguments An associative array with parameters to create * the handler object. The array indexes are the names of * the parameters and the array values are the respective * parameter values. * * Some parameters are specific of the class of each type * of handler object that is created. The following * parameters are common to all handler object classes: * * type * * Name of the type of the built-in supported class * that will be used to create the handler object. * There are currently four built-in types of handler * object classes: data, resultlob, inputfile and * outputfile. * * The data handler class is the default class. It * simply reads data from a given data string. * * The resultlob handler class is meant to read data * from a large object retrieved from a query result. * This class is not used directly by applications. * * The inputfile handler class is meant to read data * from a file to use in prepared queries with large * object field parameters. * * The outputfile handler class is meant to write to * a file data from result columns with large object * fields. The functions to read from this type of * large object do not return any data. Instead, the * data is just written to the output file with the * data retrieved from a specified large object handle. * * class * * Name of the class of the handler object that will be * created if the Type argument is not specified. This * argument should be used when you need to specify a * custom handler class. * * database * * Database object as returned by MDB2::connect. * This is an option argument needed by some handler * classes like resultlob. * * The following arguments are specific of the inputfile * handler class: * * file * * Integer handle value of a file already opened * for writing. * * file_name * * Name of a file to be opened for writing if the * File argument is not specified. * * The following arguments are specific of the outputfile * handler class: * * file * * Integer handle value of a file already opened * for writing. * * file_name * * Name of a file to be opened for writing if the * File argument is not specified. * * buffer_length * * Integer value that specifies the length of a * buffer that will be used to read from the * specified large object. * * LOB * * Integer handle value that specifies a large * object from which the data to be stored in the * output file will be written. * * result * * Integer handle value as returned by the function * MDB2::query() or MDB2::execute() that specifies * the result set that contains the large object value * to be retrieved. If the LOB argument is specified, * this argument is ignored. * * row * * Integer value that specifies the number of the * row of the result set that contains the large * object value to be retrieved. If the LOB * argument is specified, this argument is ignored. * * field * * Integer or string value that specifies the * number or the name of the column of the result * set that contains the large object value to be * retrieved. If the LOB argument is specified, * this argument is ignored. * * binary * * Boolean value that specifies whether the large * object column to be retrieved is of binary type * (blob) or otherwise is of character type (clob). * If the LOB argument is specified, this argument * is ignored. * * The following argument is specific of the data * handler class: * * data * * String of data that will be returned by the class * when it requested with the readLOB() method. * * The following argument is specific of the resultlob * handler class: * * resultLOB * * Integer handle value of a large object result * row field. * @return integer handle value that should be passed as argument insubsequent * calls to functions that retrieve data from the large object input stream. * @access public */ function createLOB($arguments) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $result = MDB2::loadFile('LOB'); if (MDB2::isError($result)) { return $result; } $class_name = 'MDB2_LOB'; if (isset($arguments['type'])) { switch ($arguments['type']) { case 'data': break; case 'resultlob': $class_name = 'MDB2_LOB_Result'; break; case 'inputfile': $class_name = 'MDB2_LOB_Input_File'; break; case 'outputfile': $class_name = 'MDB2_LOB_Output_File'; break; default: return $db->raiseError('createLOB: ' . $arguments['type'] . ' is not a valid type of large object'); } } else { if (isset($arguments['class'])) { $class = $arguments['class']; } } $lob = count($GLOBALS['_MDB2_LOBs']); $GLOBALS['_MDB2_LOBs'][] =& new $class_name(); end($GLOBALS['_MDB2_LOBs']); $lob = key($GLOBALS['_MDB2_LOBs']); if (isset($arguments['database'])) { $GLOBALS['_MDB2_LOBs'][$lob]->db =& $arguments['database']; } else { $GLOBALS['_MDB2_LOBs'][$lob]->db =& $db; } $result = $GLOBALS['_MDB2_LOBs'][$lob]->create($arguments); if (MDB2::isError($result)) { $GLOBALS['_MDB2_LOBs'][$lob]->db->datatype->destroyLOB($lob); return $result; } return $lob; }
/** * Tests that the MDB2::loadFile() method returns the expected * filename. * @dataProvider provider */ public function test_loadFile($ci) { $this->manualSetUp($ci); $filename = 'Extended'; $this->assertEquals('MDB2' . DIRECTORY_SEPARATOR . $filename . '.php', MDB2::loadFile($filename), 'loadFile'); }
<?php require_once "../DBInterface.php"; require_once "../ErrorReportEnabler.php"; MDB2::loadFile("Date"); $sql = "SELECT (" . MDB2_Date::mdbNow() . " - " . MDB2_Date::unix2Mdbstamp(strtotime('Jan 18, 2007')) . ")"; print "<p>{$sql}</p>"; $result = query($conn, $sql); print_r($result->fetchRow());
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY| // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | // | POSSIBILITY OF SUCH DAMAGE. | // +----------------------------------------------------------------------+ // | Author: Igor Feghali <*****@*****.**> | // +----------------------------------------------------------------------+ // // $Id: parse.php,v 1.4 2006/08/17 10:57:37 lsmith Exp $ // #ini_set('include_path', '../../'.PATH_SEPARATOR.ini_get('include_path')); #ini_set('include_path', '../../../MDB2'.PATH_SEPARATOR.ini_get('include_path')); require_once 'MDB2.php'; $dsn = array('phptype' => 'mysql', 'username' => 'root', 'password' => '', 'hostspec' => 'localhost'); $options = array(); MDB2::loadFile('Schema'); $manager =& MDB2_Schema::factory($dsn, $options); if (MDB2::isError($manager)) { die($manager->getUserinfo()); } $database_definition = $manager->parseDatabaseDefinitionFile('./schema.xml'); $manager->db->setOption('disable_query', true); $manager->db->setOption('debug', true); $manager->writeInitialization($database_definition); ?> <pre> <?php var_dump($database_definition); var_dump($manager->db->getDebugOutput()); ?> </pre>
/** * Tests that the MDB2::loadFile() method returns the expected * filename. */ function test_loadFile() { $filename = 'Extended'; $this->assertEquals('MDB2/' . $filename . '.php', MDB2::loadFile($filename), 'loadFile'); }
/** * Make setOption('result_wrap_class') work without convoluted query() calls * @see https://pear.php.net/bugs/bug.php?id=16970 * @dataProvider provider */ public function testRequest16970($ci) { $this->manualSetUp($ci); $data = $this->populateUserData(1); $this->db->setFetchMode(MDB2_FETCHMODE_ASSOC); MDB2::loadFile('Iterator'); switch ($this->db->phptype) { case 'mysqli': $expect = 'mysqli_result'; break; default: $expect = 'resource'; } // Regular behavior. $res = $this->db->query('SELECT * FROM ' . $this->table_users); $this->assertInstanceOf('MDB2_Result_Common', $res); $res = $this->db->query('SELECT * FROM ' . $this->table_users, null, true); $this->assertInstanceOf('MDB2_Result_Common', $res); $res = $this->db->query('SELECT * FROM ' . $this->table_users, null, false); if ($expect == 'resource') { $this->assertInternalType('resource', $res); } else { $this->assertInstanceOf($expect, $res); } $res = $this->db->query('SELECT * FROM ' . $this->table_users, null, true, true); $this->assertInstanceOf('MDB2_Result_Common', $res); $res = $this->db->query('SELECT * FROM ' . $this->table_users, null, true, false); $this->assertInstanceOf('MDB2_Result_Common', $res); $res = $this->db->query('SELECT * FROM ' . $this->table_users, null, true, 'MDB2_BufferedIterator'); $this->assertEquals('MDB2_BufferedIterator', get_class($res)); // Setting third parameter to false forces raw results to be returned. $res = $this->db->query('SELECT * FROM ' . $this->table_users, null, false, true); if ($expect == 'resource') { $this->assertInternalType('resource', $res); } else { $this->assertInstanceOf($expect, $res); } $res = $this->db->query('SELECT * FROM ' . $this->table_users, null, false, false); if ($expect == 'resource') { $this->assertInternalType('resource', $res); } else { $this->assertInstanceOf($expect, $res); } $res = $this->db->query('SELECT * FROM ' . $this->table_users, null, false, 'MDB2_BufferedIterator'); if ($expect == 'resource') { $this->assertInternalType('resource', $res); } else { $this->assertInstanceOf($expect, $res); } // Utilize a default result wrap class. $this->db->setOption('result_wrap_class', 'MDB2_Iterator'); $res = $this->db->query('SELECT * FROM ' . $this->table_users); $this->assertEquals('MDB2_Iterator', get_class($res)); $res = $this->db->query('SELECT * FROM ' . $this->table_users, null, true); $this->assertEquals('MDB2_Iterator', get_class($res)); $res = $this->db->query('SELECT * FROM ' . $this->table_users, null, false); if ($expect == 'resource') { $this->assertInternalType('resource', $res); } else { $this->assertInstanceOf($expect, $res); } $res = $this->db->query('SELECT * FROM ' . $this->table_users, null, true, true); $this->assertEquals('MDB2_Iterator', get_class($res)); $res = $this->db->query('SELECT * FROM ' . $this->table_users, null, true, false); $this->assertInstanceOf('MDB2_Result_Common', $res); $res = $this->db->query('SELECT * FROM ' . $this->table_users, null, true, 'MDB2_BufferedIterator'); $this->assertEquals('MDB2_BufferedIterator', get_class($res)); // Setting third parameter to false forces raw results to be returned. $res = $this->db->query('SELECT * FROM ' . $this->table_users, null, false, true); if ($expect == 'resource') { $this->assertInternalType('resource', $res); } else { $this->assertInstanceOf($expect, $res); } $res = $this->db->query('SELECT * FROM ' . $this->table_users, null, false, false); if ($expect == 'resource') { $this->assertInternalType('resource', $res); } else { $this->assertInstanceOf($expect, $res); } $res = $this->db->query('SELECT * FROM ' . $this->table_users, null, false, 'MDB2_BufferedIterator'); if ($expect == 'resource') { $this->assertInternalType('resource', $res); } else { $this->assertInstanceOf($expect, $res); } }