Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

git-svn-id: svn://dklab.ru/lib/DbSimple/trunk@96 78bb956b-1e24-0410-b…

…8d0-c528fdc9eae3
  • Loading branch information...
commit 950cfc3692ff128523b54143d00f6d25c07bead6 1 parent 4ff11e2
dk authored
Showing with 36 additions and 0 deletions.
  1. +36 −0 test/DbSimple/connect.php
View
36 test/DbSimple/connect.php
@@ -0,0 +1,36 @@
+<?php ## Ïîäêëþ÷åíèå ê ÁÄ.
+require_once "../../lib/config.php";
+require_once "DbSimple/DSN.php";
+
+// Ïîëó÷àåì ïàðîëü äëÿ äîñòóïà ê ÁÄ èç âíåøíåãî ôàéëà,
+// ÷òîáû íå ïîäñìàòðèâàëè.
+@include "{$_SERVER['DOCUMENT_ROOT']}/../forum/dbconfig.php";
+if (!empty($dbpasswd)) {
+ // Ýòî ïàðàìåòðû ïîäêëþ÷åíèÿ äëÿ dklab.
+ $dsn = "mysql://$dbuser:$dbpasswd@localhost/$dbname";
+} else {
+ // À ýòî - äëÿ âàñ. Âû æå íå dklab...
+ $dsn = "mysql://Ëîãèí:Ïàðîëü@Õîñò/Áàçà";
+}
+
+// Ïîäêëþ÷àåìñÿ ê ÁÄ.
+$DATABASE = DbSimple_DSN::connect($dsn);
+
+// Óñòàíàâëèâàåì îáðàáîò÷èê îøèáîê.
+$DATABASE->set_error_handler('databaseErrorHandler');
+
+// Ñòàðòóåì íîâóþ òðàíçàêöèþ.
+$DB = $DATABASE->transaction();
+
+// Êîä îáðàáîò÷èêà îøèáîê SQL.
+function databaseErrorHandler($message, $info)
+{
+ // Åñëè èñïîëüçîâàëàñü @, íè÷åãî íå äåëàòü.
+ if (!error_reporting()) return;
+ // Âûâîäèì ïîäðîáíóþ èíôîðìàöèþ îá îøèáêå.
+ echo "SQL Error: $message<br><pre>";
+ print_r($info);
+ echo "</pre>";
+ exit();
+}
+?>
Please sign in to comment.
Something went wrong with that request. Please try again.