Sunday, November 14, 2010

PHP Basics: Connect to MySql and Query

//open conn to db
mysql_connect('dbhostserver','dbusername','password') or die("Failure to connect to db");

mysql_select_db('dbname');

$query = "SELECT stuff FROM tablename";
$result = mysql_query($query);
while($name_row = mysql_fetch_row($result)){
    print("$name_row[0]<BR>\n");
}

No comments: