ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilSCORM13DB Class Reference
+ Collaboration diagram for ilSCORM13DB:

Public Member Functions

 __construct ($dsn, $login, $password, $type='mysql')
 init ($dsn, $login, $password, $type='mysql')
 addQueries ()
 getLastId ()
 getType ()
getRecord ($tableOrView, $idname, $idvalue)
 setRecord ($tableOrView, $row, $idname=null)
getRecords ($tableOrView, $idname=null, $idvalues=null, $order=null, $paging=null)
 setRecords ($tableOrView, $rows, $idname=null)
 removeRecord ($table, $idname, $idvalue)
 removeRecords ($tables, $idnames, $idvalues)
query ($query, $params=null, $order=null, $paging=null, $fetchType=PDO::FETCH_ASSOC)
 exec ($queries, $params=null, &$result=null)
 exec('delete...') exec('delete...
 begin ()
 commit ()
 rollback ()
 il_to_pdo_dsn ($il_dsn)

Static Public Attributes

static $DB

Private Member Functions

 getDSN ()
 getDB ()
 escapeName ($name)
 setLastId ($id)

Private Attributes

 $db
 $dsn
 $type
 $brackets
 $lastId

Static Private Attributes

static $DSN
static $TYPE
static $BRACKETS
static $LAST_ID
static $ERRORS
static $BRACKETS_LIST
static $errors
static $SQLCOMMAND = array()

Detailed Description

Constructor & Destructor Documentation

ilSCORM13DB::__construct (   $dsn,
  $login,
  $password,
  $type = 'mysql' 
)

Definition at line 56 of file ilSCORM13DB.php.

References $dsn, and $type.

{
try {
self::$DB = new PDO($dsn, $login, $password);
} catch (PDOException $e) {
error_log("Error!: " . $e->getMessage());
}
$this->dsn = $dsn;
$this->brackets = self::$BRACKETS_LIST[$type];
$this->type = is_null($type) ? substr($dsn, 0, strpos($dsn, ':')) : $type;
$this->brackets = self::$BRACKETS_LIST[$this->type];
}

Member Function Documentation

ilSCORM13DB::addQueries ( )

Definition at line 82 of file ilSCORM13DB.php.

Referenced by exec(), and query().

{
require_once("./Modules/Scorm2004/classes/ilSCORM13Player_mysql.php");
}

+ Here is the caller graph for this function:

ilSCORM13DB::begin ( )

Definition at line 358 of file ilSCORM13DB.php.

References getDB().

{
self::getDB()->beginTransaction();
self::$ERRORS = 0;
}

+ Here is the call graph for this function:

ilSCORM13DB::commit ( )

Definition at line 364 of file ilSCORM13DB.php.

References $ERRORS, and getDB().

{
self::$ERRORS
? self::getDB()->rollBack()
: self::getDB()->commit();
return self::$ERRORS;
}

+ Here is the call graph for this function:

ilSCORM13DB::escapeName (   $name)
private

Definition at line 116 of file ilSCORM13DB.php.

References $BRACKETS.

Referenced by getRecord(), getRecords(), query(), removeRecords(), and setRecords().

{
$b = $this && $this instanceof ilSCORM13DB
? $this->brackets
return $b[0] . preg_replace('/[^\w_.-]/', '_', $name) . $b[1];
}

+ Here is the caller graph for this function:

ilSCORM13DB::exec (   $queries,
  $params = null,
$result = null 
)

exec('delete...') exec('delete...

id=?', array(231)) exec('insert... id=?', array(array(231), array(130))) exec(array('select... id=?', 'select2... id=?'), array(array(231))) exec(array('select... id=?', 'select2... id=?'), array(array(231), array(130)))

erstelle gleich dimensionale arrays f�r $queries und $params

Definition at line 304 of file ilSCORM13DB.php.

References $d, $result, addQueries(), and getDB().

Referenced by removeRecords().

{
if (!is_array($queries))
{
$r = self::exec(array($queries), $params);
return $r[0];
}
if (!is_array($params))
{
$params = array();
}
if (!is_array(current($params)))
{
$params = array($params);
}
//$d = new PDO(self::getDSN());
foreach ($queries as $i => &$q)
{
if ($s = $d->prepare($sql = (self::$SQLCOMMAND[$q] ? self::$SQLCOMMAND[$q] : $q)))
{
error_log("SQL-Command: ".self::$SQLCOMMAND[$q]);
$q = 0;
$r = array();
$ps = is_array($params) ? $params[$i % count($params)] : null;
if (!is_array(current($ps)))
{
$ps = array($ps);
}
foreach ($ps as $p)
{
$q+=$s->execute($p);
$arr = $s->errorInfo();
file_put_contents('/tmp/sql.log', implode("\n", array('', date('c'), $sql, var_export($p, true),var_export($arr,true))), FILE_APPEND);
if (is_array($result))
{
count($queries)<2
? $result = $s->fetchAll(PDO::FETCH_ASSOC)
: $result[] = $s->fetchAll(PDO::FETCH_ASSOC);
}
}
}
else
{
// prepare failed
}
}
unset($d);
return $queries;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilSCORM13DB::getDB ( )
private

Definition at line 109 of file ilSCORM13DB.php.

References $DB.

Referenced by begin(), commit(), exec(), getLastId(), query(), removeRecords(), rollback(), and setRecords().

{
return $this && $this instanceof ilSCORM13DB
? $this->db
}

+ Here is the caller graph for this function:

ilSCORM13DB::getDSN ( )
private

Definition at line 102 of file ilSCORM13DB.php.

References $DSN.

{
return $this && $this instanceof ilSCORM13DB
? $this->dsn
}
ilSCORM13DB::getLastId ( )

Definition at line 87 of file ilSCORM13DB.php.

References $LAST_ID, and getDB().

{
return self::getDB()->lastInsertId();
return $this && $this instanceof ilSCORM13DB
? $this->lastId
}

+ Here is the call graph for this function:

& ilSCORM13DB::getRecord (   $tableOrView,
  $idname,
  $idvalue 
)

Definition at line 131 of file ilSCORM13DB.php.

References escapeName(), and query().

{
if (!is_string($idname) || !is_numeric($idvalue))
{
return false;
}
$q = 'SELECT * FROM ' . self::escapeName($tableOrView) . ' WHERE ' . self::escapeName($idname) . '=' . $idvalue;
$r = self::query($q);
return $r[0];
}

+ Here is the call graph for this function:

& ilSCORM13DB::getRecords (   $tableOrView,
  $idname = null,
  $idvalues = null,
  $order = null,
  $paging = null 
)

Definition at line 148 of file ilSCORM13DB.php.

References escapeName(), and query().

{
$tableOrView = self::escapeName($tableOrView);
$q = "SELECT * FROM $tableOrView";
if (is_string($idname) && is_array($idvalues))
{
$idname = self::escapeName($idname);
foreach ($idvalues as &$idvalue)
{
if (!is_numeric($idvalue)) return false;
$idvalue = "$idname=$idvalue";
}
$q .= ' ' . implode(' OR ', $idvalues);
}
return self::query($q, null, $order, $paging);
}

+ Here is the call graph for this function:

ilSCORM13DB::getType ( )

Definition at line 95 of file ilSCORM13DB.php.

References $TYPE.

Referenced by setRecords().

{
return $this && $this instanceof ilSCORM13DB
? $this->type
}

+ Here is the caller graph for this function:

ilSCORM13DB::il_to_pdo_dsn (   $il_dsn)

Definition at line 378 of file ilSCORM13DB.php.

{
$pattern = '/([a-z]+)(:\/\/)([^:]*)(:)([^@]*)(@)([^\/]+)(\/)(.*)/i';
preg_match($pattern, $il_dsn, $matches);
$pdo_dsn[0]=$matches[1].":dbname=".$matches[9].";host=".$matches[7];
$pdo_dsn[1]=$matches[3];
$pdo_dsn[2]=$matches[5];
return $pdo_dsn;
}
ilSCORM13DB::init (   $dsn,
  $login,
  $password,
  $type = 'mysql' 
)

Definition at line 70 of file ilSCORM13DB.php.

References $dsn, $TYPE, and $type.

{
try {
self::$DB = new PDO($dsn, $login, $password);
} catch (PDOException $e) {
error_log("Error!: " . $e->getMessage());
}
self::$DSN = $dsn;
self::$TYPE = is_null($type) ? substr($dsn, 0, strpos($dsn, ':')) : $type;
self::$BRACKETS = self::$BRACKETS_LIST[self::$TYPE];
}
& ilSCORM13DB::query (   $query,
  $params = null,
  $order = null,
  $paging = null,
  $fetchType = PDO::FETCH_ASSOC 
)

Definition at line 258 of file ilSCORM13DB.php.

References $d, $query, addQueries(), escapeName(), and getDB().

Referenced by getRecord(), and getRecords().

{
$r = array();
$q = array(self::$SQLCOMMAND[$query] ? self::$SQLCOMMAND[$query] : $query);
if (is_array($order))
{
$o = array();
foreach ($order as $k => $v)
{
$o[] = self::escapeName($k) . ' ' . ($v ? 'ASC' : 'DESC');
}
$q[] = 'ORDER BY ' . implode(', ', $o);
}
if (is_array($paging))
{
if (is_int($o = $paging['count']))
{
// MySQL Style
$q[] = "LIMIT $o";
if (is_int($o = $paging['offset']))
{
$q[] = "OFFSET $o";
}
}
}
$q = implode(' ', $q);
$s = $d->prepare($q);
$s->execute($params);
$arr = $s->errorInfo();
file_put_contents('/tmp/sql.log', implode("\n", array('', date('c'), $q, var_export($params, true),var_export($arr,true))), FILE_APPEND);
$r = $s->fetchAll($fetchType);
unset($d);
return $r;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilSCORM13DB::removeRecord (   $table,
  $idname,
  $idvalue 
)

Definition at line 220 of file ilSCORM13DB.php.

References removeRecords().

{
self::removeRecords($table, $idname, array($idvalue));
}

+ Here is the call graph for this function:

ilSCORM13DB::removeRecords (   $tables,
  $idnames,
  $idvalues 
)

Definition at line 225 of file ilSCORM13DB.php.

References $d, escapeName(), exec(), and getDB().

Referenced by removeRecord().

{
if (!is_array($idvalues))
{
return false;
}
//$d = new PDO(self::getDSN());
if (!is_array($tables))
{
$tables = array($tables);
}
if (!is_array($idnames))
{
$idnames = array($idnames);
}
$tables = array_reverse($tables);
foreach ($tables as $i => &$table)
{
$table = self::escapeName($table);
$idname = $idnames[$i % count($idnames)];
if (!is_string($idname)) return false;
$idname = self::escapeName($idname);
$q = "DELETE FROM $table WHERE $idname=?";
foreach ($idvalues as $idvalue)
{
$table = self::exec($q, $idvalue);
}
}
unset($d);
return array_reverse($tables);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilSCORM13DB::rollback ( )

Definition at line 372 of file ilSCORM13DB.php.

References getDB().

{
self::getDB()->rollBack();
}

+ Here is the call graph for this function:

ilSCORM13DB::setLastId (   $id)
private

Definition at line 124 of file ilSCORM13DB.php.

Referenced by setRecords().

{
$this && $this instanceof ilSCORM13DB
? $this->lastId = $id
: self::$LAST_ID = $id;
}

+ Here is the caller graph for this function:

ilSCORM13DB::setRecord (   $tableOrView,
  $row,
  $idname = null 
)

Definition at line 142 of file ilSCORM13DB.php.

References $row, and setRecords().

{
$r = self::setRecords($tableOrView, array($row), $idname);
return $r[0];
}

+ Here is the call graph for this function:

ilSCORM13DB::setRecords (   $tableOrView,
  $rows,
  $idname = null 
)

Definition at line 165 of file ilSCORM13DB.php.

References $d, $row, $type, escapeName(), getDB(), getType(), and setLastId().

Referenced by setRecord().

{
//$d = new PDO(self::getDSN());
$r = 0;
if (!is_array($row = $rows[0]))
{
return false;
}
$tableOrView = self::escapeName($tableOrView);
$q = array();
if (is_string($idname)) {
$idvalue = $row[$idname];
$idname = self::escapeName($idname);
}
$u = is_numeric($idvalue);
if ($u)
{
foreach (array_keys($row) as $k)
{
$q[] = self::escapeName($k) . '=?';
}
$q = implode(', ', $q);
$q = "UPDATE $tableOrView SET $q WHERE $idname=$idvalue";
}
else
{
foreach (array_keys($row) as $k)
{
$q[] = self::escapeName($k);
}
$q = implode(', ', $q);
$q = "INSERT INTO $tableOrView ($q) VALUES (" . str_pad('', count($row)*2-1, '?,') . ')';
}
//echo "<br>$q";
if ($s = $d->prepare($q))
{
foreach ($rows as &$row)
{
$row = $s->execute(array_values($row));
$arr = $s->errorInfo();
file_put_contents('/tmp/sql.log', implode("\n", array('', date('c'), $sql, var_export($q, true),var_export($arr,true))), FILE_APPEND);
if (!$u && is_string($idname) && $row)
{
$row = $d->lastInsertId();
}
}
}
unset($d);
return $rows;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

ilSCORM13DB::$BRACKETS
staticprivate

Definition at line 37 of file ilSCORM13DB.php.

Referenced by escapeName().

ilSCORM13DB::$brackets
private

Definition at line 49 of file ilSCORM13DB.php.

ilSCORM13DB::$BRACKETS_LIST
staticprivate
Initial value:
array(
'mysql' => '``',
'sqlite' => '""',
)

Definition at line 40 of file ilSCORM13DB.php.

ilSCORM13DB::$DB
static

Definition at line 34 of file ilSCORM13DB.php.

Referenced by getDB().

ilSCORM13DB::$db
private

Definition at line 46 of file ilSCORM13DB.php.

ilSCORM13DB::$DSN
staticprivate

Definition at line 35 of file ilSCORM13DB.php.

Referenced by getDSN().

ilSCORM13DB::$dsn
private

Definition at line 47 of file ilSCORM13DB.php.

Referenced by __construct(), and init().

ilSCORM13DB::$ERRORS
staticprivate

Definition at line 39 of file ilSCORM13DB.php.

Referenced by commit().

ilSCORM13DB::$errors
staticprivate

Definition at line 51 of file ilSCORM13DB.php.

ilSCORM13DB::$LAST_ID
staticprivate

Definition at line 38 of file ilSCORM13DB.php.

Referenced by getLastId().

ilSCORM13DB::$lastId
private

Definition at line 50 of file ilSCORM13DB.php.

ilSCORM13DB::$SQLCOMMAND = array()
staticprivate

Definition at line 53 of file ilSCORM13DB.php.

ilSCORM13DB::$TYPE
staticprivate

Definition at line 36 of file ilSCORM13DB.php.

Referenced by getType(), and init().

ilSCORM13DB::$type
private

Definition at line 48 of file ilSCORM13DB.php.

Referenced by __construct(), init(), and setRecords().


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