Esempio n. 1
0
 /**
 	Initialises a mysql prepared statement.
 
 	@param	$oDb	The mysql link resource.
 	@param	$sQuery	The query.
 	@throw	InvalidArgumentException	The database is not an instance of weeMySQLDatabase nor weeMySQLiDatabase.
 */
 public function __construct(weeDatabase $oDb, $rLink, $sQuery)
 {
     is_resource($rLink) && get_resource_type($rLink) == 'mysql link' or burn('InvalidArgumentException', sprintf(_WT('The given variable must be a resource of type "%s".'), 'mysql link'));
     $oDb->is('mysql') or burn('InvalidArgumentException', _WT('The underlying DBMS of the given database is not handled by this class.'));
     preg_match_all('/:([\\w_]+)/', $sQuery, $aMatches, PREG_OFFSET_CAPTURE);
     $s = '';
     $iOffset = 0;
     foreach ($aMatches[1] as $aMatch) {
         $this->aParametersMap[] = $aMatch[0];
         $s .= substr($sQuery, $iOffset, $aMatch[1] - $iOffset - 1) . '?';
         $iOffset = $aMatch[1] + strlen($aMatch[0]);
     }
     $s .= substr($sQuery, $iOffset);
     $this->sStatementName = 'st_' . md5($sQuery);
     $this->oDb = $oDb;
     $this->rLink = $rLink;
     $s = 'PREPARE ' . $this->sStatementName . ' FROM ' . $this->oDb->escape($s);
     mysql_unbuffered_query($s, $this->rLink) !== false or burn('DatabaseException', sprintf(_WT("Failed to prepare the query with the following error:\n%s"), mysql_error($this->rLink)));
 }
Esempio n. 2
0
 /**
 	Initializes a new database meta.
 
 	@param	$oDb	The database to query.
 	@throw	InvalidArgumentException	The underlying DBMS of the given database is not handled by the class.
 */
 public function __construct(weeDatabase $oDb)
 {
     $this->mDBMS !== null or burn('IllegalStateException', sprintf(_WT('The property $%s must not be empty.'), 'mDBMS'));
     is_string($this->mDBMS) ? $oDb->is($this->mDBMS) : in_array($oDb->is(), $this->mDBMS) or burn('InvalidArgumentException', _WT('The underlying DBMS of the given database is not handled by this class.'));
     $this->oDb = $oDb;
 }