59 self::$DB =
new PDO(
$dsn, $login, $password);
60 }
catch (PDOException $e) {
61 error_log(
"Error!: " . $e->getMessage());
64 $this->brackets = self::$BRACKETS_LIST[
$type];
66 $this->brackets = self::$BRACKETS_LIST[
$this->type];
73 self::$DB =
new PDO(
$dsn, $login, $password);
74 }
catch (PDOException $e) {
75 error_log(
"Error!: " . $e->getMessage());
79 self::$BRACKETS = self::$BRACKETS_LIST[
self::$TYPE];
84 require_once(
"./Modules/Scorm2004/classes/ilSCORM13Player_mysql.php");
121 return $b[0] . preg_replace(
'/[^\w_.-]/',
'_',
$name) . $b[1];
127 ? $this->lastId = $id
128 : self::$LAST_ID = $id;
131 public function &
getRecord($tableOrView, $idname, $idvalue)
133 if (!is_string($idname) || !is_numeric($idvalue))
148 public function &
getRecords($tableOrView, $idname=null, $idvalues=null, $order=null, $paging=null)
151 $q =
"SELECT * FROM $tableOrView";
152 if (is_string($idname) && is_array($idvalues))
155 foreach ($idvalues as &$idvalue)
157 if (!is_numeric($idvalue))
return false;
158 $idvalue =
"$idname=$idvalue";
160 $q .=
' ' . implode(
' OR ', $idvalues);
170 if (!is_array(
$row = $rows[0]))
176 if (is_string($idname)) {
177 $idvalue =
$row[$idname];
180 $u = is_numeric($idvalue);
183 foreach (array_keys(
$row) as $k)
187 $q = implode(
', ', $q);
188 $q =
"UPDATE $tableOrView SET $q WHERE $idname=$idvalue";
192 foreach (array_keys(
$row) as $k)
196 $q = implode(
', ', $q);
197 $q =
"INSERT INTO $tableOrView ($q) VALUES (" . str_pad(
'', count(
$row)*2-1,
'?,') .
')';
200 if ($s =
$d->prepare($q))
203 foreach ($rows as &
$row)
205 $row = $s->execute(array_values($row));
206 $arr = $s->errorInfo();
207 file_put_contents(
'/tmp/sql.log', implode(
"\n", array(
'', date(
'c'), $sql, var_export($q,
true),var_export($arr,
true))), FILE_APPEND);
209 if (!$u && is_string($idname) && $row)
211 $row =
$d->lastInsertId();
227 if (!is_array($idvalues))
233 if (!is_array($tables))
235 $tables = array($tables);
237 if (!is_array($idnames))
239 $idnames = array($idnames);
241 $tables = array_reverse($tables);
242 foreach ($tables as $i => &$table)
245 $idname = $idnames[$i % count($idnames)];
246 if (!is_string($idname))
return false;
248 $q =
"DELETE FROM $table WHERE $idname=?";
249 foreach ($idvalues as $idvalue)
255 return array_reverse($tables);
258 public function &
query(
$query, $params=null, $order=null, $paging=null, $fetchType=PDO::FETCH_ASSOC)
264 if (is_array($order))
267 foreach ($order as $k => $v)
271 $q[] =
'ORDER BY ' . implode(
', ', $o);
273 if (is_array($paging))
275 if (is_int($o = $paging[
'count']))
279 if (is_int($o = $paging[
'offset']))
285 $q = implode(
' ', $q);
286 $s =
$d->prepare($q);
287 $s->execute($params);
288 $arr = $s->errorInfo();
289 file_put_contents(
'/tmp/sql.log', implode(
"\n", array(
'', date(
'c'), $q, var_export($params,
true),var_export($arr,
true))), FILE_APPEND);
290 $r = $s->fetchAll($fetchType);
304 public function exec($queries, $params=null, &$result = null)
306 if (!is_array($queries))
311 if (!is_array($params))
315 if (!is_array(current($params)))
317 $params = array($params);
322 foreach ($queries as $i => &$q)
324 if ($s =
$d->prepare($sql = (self::$SQLCOMMAND[$q] ? self::$SQLCOMMAND[$q] : $q)))
326 error_log(
"SQL-Command: ".self::$SQLCOMMAND[$q]);
329 $ps = is_array($params) ? $params[$i % count($params)] : null;
330 if (!is_array(current($ps)))
337 $arr = $s->errorInfo();
338 file_put_contents(
'/tmp/sql.log', implode(
"\n", array(
'', date(
'c'), $sql, var_export($p,
true),var_export($arr,
true))), FILE_APPEND);
340 if (is_array($result))
343 ? $result = $s->fetchAll(PDO::FETCH_ASSOC)
344 : $result[] = $s->fetchAll(PDO::FETCH_ASSOC);
380 $pattern =
'/([a-z]+)(:\/\/)([^:]*)(:)([^@]*)(@)([^\/]+)(\/)(.*)/i';
381 preg_match($pattern, $il_dsn, $matches);
382 $pdo_dsn[0]=$matches[1].
":dbname=".$matches[9].
";host=".$matches[7];
383 $pdo_dsn[1]=$matches[3];
384 $pdo_dsn[2]=$matches[5];