I come across this: -
PHP Error Handling: die () Vs trigger_error () Vs throw Exception
and realized that throw exception is better
How can I replace die and use the throw exception here in this code: -
<?php # FileName="Connection_php_mysql.htm" # Type="MYSQL" # HTTP="true" $hostname_db = "localhost"; $database_db = "database"; $username_db = "root"; $password_db = "password"; $db = mysqli_connect($hostname_db, $username_db, $password_db) or die("Unable to connect with Database"); ?>
try { if ($db = mysqli_connect($hostname_db, $username_db, $password_db)) { //do something } else { throw new Exception('Unable to connect'); } } catch(Exception $e) { echo $e->getMessage(); }
Described here is http://ie2.php.net/manual/en/mysqli.error.php
if (mysqli_connect_errno()) { throw new RuntimeException("Connect failed: %s\n", mysqli_connect_error()); }
Source: https://habr.com/ru/post/911482/More articles:Outlets: sometimes (rarely) packets are lost during reception - c #Python dictionary classes (which are class objects) are compared with multiple comparators - pythonhttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/911479/no-row-returned-from-db-but-there-are-records-to-be-returned&usg=ALkJrhipcn_jEyF_zhN2Zi0JEM69c9-DFAIs it possible to automatically generate llvm C ++ api code from LLVM-IR? - clangTomcat configuration in IntelliJ IDEA - intellij-ideaHow to run a batch file while keeping the console window hidden? - batch-fileWhy is auto_increment underlined? - sqlWhy doesn't font customization work in gvim? - vimHow to cancel a session associated with UIButton - iosOverride system property in Java (no code) - javaAll Articles