Page 1 of 1

Querycheck

Posted: Sat Dec 13, 2003 5:28 am
by Overunner
How important is it to check each query that has been made to the database? E.g

Code: Select all

<?php
$query = "SELECT Email FROM customers WHERE Username = '$username'";
$result = mysql_query($query,$connection);

if (!$result)
   die("Error...");
?>
Or should I just check the queries regarding user login and database connections???

Posted: Sat Dec 13, 2003 6:17 am
by JayBird
it depends how important it is that your query is succesful

Mark

Re: Querycheck

Posted: Sat Dec 13, 2003 6:48 am
by lazy_yogi
You should validate each query to ensure no errors

Code: Select all

$query = "SELECT ......";

$result = mysql_query($query,$connection)
    OR die("Error.....") # or do something else

Posted: Sat Dec 13, 2003 3:39 pm
by DuFF
Here is a safe way to connect and query the database:

Code: Select all

<?php
@mysql_connect($host,$user,$password) or die("Unable to connect to MySQL database: " . mysql_error());
@mysql_select_db($db) or die( "Unable to select MySQL database: " . mysql_error());
$query = "SELECT ...";
$result = mysql_query($query) or die("MySQL query failed: " . mysql_error());
?>