Is this the correct way to use die()? $con = mysql_connect("localhost","tonybrar","***********") or die('Error: ' . mysql_error()); PHP: Thanks in advance, Tony
If you are looking for a connection script that has die() in it you seem to have it right. The way I do it is a bit longer but it does the same thing: <?php $link = mysql_connect('localhost', 'DBUSER', 'DBPASS '); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db('DB'); ?> PHP: If you are looking to use die() to confirm a query you could use something like this function function confirm_query($result_set){ if(!$result_set){ die("Database query failed: ".mysql_error()); } } $query = mysql_query("SOME QUERY HERE"); confirm_query($query); PHP:
As some advice you should not use mysql_* any more as it is deprecated. Use PDO or mysqli_* to interact with databases. An example to get you started: $db = new PDO("mysql:dbname=databasename;host=127.0.0.1", "username", "password"); $q = $db->prepare("SELECT * FROM table WHERE condition = 'predicate'"); $q->execute(); $row = $q->fetch(PDO::FETCH_ASSOC); Code (markup):