View Single Post
Old 04-06-2004, 10:30 AM   #5 (permalink)
cliche
Rookie
 
cliche's Avatar
 
Location: Oxford, UK
Thought someone should write about how to connect. Hell, I'm bored and hopefully someone will find it useful!
Code:
$link = mysql_connect("localhost", "<user>", "<password>") or die("Could not connect");
mysql_select_db("<Database Name>") or die("Could not select database");
$result = mysql_query("SELECT * FROM <table> WHERE <whatever>",$link);
while ($row = mysql_fetch_array($result)) {
   <do stuff with the row>
}
You can use 'mysql_fetch_array' to get the column names into things like $row['surname'], or use 'mysql_fetch_row' to end up with $row[1] etc... which can be a bugger to debug.

Hope that's of some use
__________________
I can't understand why people are frightened of new ideas. I'm frightened of the old ones. -- John Cage (1912 - 1992)
cliche is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47