Querycheck

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Overunner
Forum Newbie
Posts: 9
Joined: Sat Dec 13, 2003 5:28 am

Querycheck

Post 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???
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

it depends how important it is that your query is succesful

Mark
User avatar
lazy_yogi
Forum Contributor
Posts: 243
Joined: Fri Jan 24, 2003 3:27 am

Re: Querycheck

Post 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
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post 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());
?>
Post Reply