boywonder
09-03-2002, 11:47 PM
Hi I have recently dived into PHP/mysql and have learned much just from browsing these forums. I have been connecting to my database as follows and it seems to be working just fine:
$dbconnect = mysql_connect("localhost", "user", "pass") or die("unable to connect to database");
mysql_select_db("database_name") or die("unable to find database");
$result = mysql_query("SELECT * FROM table") or die ("query failed");
mysql_close($dbconnect);
As I browse the threads here however I see many people doing it a little differently, for instance,
Using the connection variable as the second argument in mysql_select_db(), or using the database name as an argument in mysql_query(). I understand these are optional arguments for those functions but why do many people see the need to include them?
Also some save the query (and just about everything else) as a variable first.
So is the way I'm doing it inefficient or not the best way to go? I would really like to learn this the right way from the start.
PS - I know using @ before a function is supposed to supress errors, but isn't that what die() does... what's the difference?
Thank you kindly for any insight/advice.:thumbsup:
$dbconnect = mysql_connect("localhost", "user", "pass") or die("unable to connect to database");
mysql_select_db("database_name") or die("unable to find database");
$result = mysql_query("SELECT * FROM table") or die ("query failed");
mysql_close($dbconnect);
As I browse the threads here however I see many people doing it a little differently, for instance,
Using the connection variable as the second argument in mysql_select_db(), or using the database name as an argument in mysql_query(). I understand these are optional arguments for those functions but why do many people see the need to include them?
Also some save the query (and just about everything else) as a variable first.
So is the way I'm doing it inefficient or not the best way to go? I would really like to learn this the right way from the start.
PS - I know using @ before a function is supposed to supress errors, but isn't that what die() does... what's the difference?
Thank you kindly for any insight/advice.:thumbsup: