diff --git a/examples/connecting-to-databases.php b/examples/connecting-to-databases.php index d9bf4375..cfc5b6a6 100644 --- a/examples/connecting-to-databases.php +++ b/examples/connecting-to-databases.php @@ -40,18 +40,7 @@ try { echo "

\n"; -// connects to MySQL using DSN -echo '

Connecting to MySQL: '; -try { - dibi::connect('driver=mysql&host=localhost&username=root&password=xxx&database=test&charset=cp1250'); - echo 'OK'; -} catch (Dibi\Exception $e) { - echo get_class($e), ': ', $e->getMessage(), "\n"; -} -echo "

\n"; - - -// connects to MySQLi using array +// connects to MySQLi echo '

Connecting to MySQLi: '; try { dibi::connect([ diff --git a/src/Dibi/Connection.php b/src/Dibi/Connection.php index 82059fff..776425bc 100644 --- a/src/Dibi/Connection.php +++ b/src/Dibi/Connection.php @@ -56,9 +56,11 @@ class Connection implements IConnection public function __construct($config, string $name = null) { if (is_string($config)) { + trigger_error(__METHOD__ . '() Configuration should be array.', E_USER_DEPRECATED); parse_str($config, $config); } elseif ($config instanceof Traversable) { + trigger_error(__METHOD__ . '() Configuration should be array.', E_USER_DEPRECATED); $tmp = []; foreach ($config as $key => $val) { $tmp[$key] = $val instanceof Traversable ? iterator_to_array($val) : $val; @@ -66,7 +68,7 @@ class Connection implements IConnection $config = $tmp; } elseif (!is_array($config)) { - throw new \InvalidArgumentException('Configuration must be array, string or object.'); + throw new \InvalidArgumentException('Configuration must be array.'); } Helpers::alias($config, 'username', 'user'); diff --git a/tests/dibi/Connection.connect.phpt b/tests/dibi/Connection.connect.phpt index 44e84eca..25112d18 100644 --- a/tests/dibi/Connection.connect.phpt +++ b/tests/dibi/Connection.connect.phpt @@ -30,8 +30,8 @@ test(function () use ($config) { // lazy }); -test(function () use ($config) { // query string - $conn = new Connection(http_build_query($config, '', '&')); +test(function () use ($config) { + $conn = new Connection($config); Assert::true($conn->isConnected()); Assert::null($conn->getConfig('lazy'));