Archive:PHP and MySQL Programming/Database Connectivity: Difference between revisions

wikademia>Darklama
m recat sort
wikademia>Wikademia
 
(6 intermediate revisions by 3 users not shown)
Line 17: Line 17:
== Creating a Query ==
== Creating a Query ==


Once a connection to a database has been made, you will inevetably want to perform a database query. To create a query on the selected database, we use the mysql_query() function. If you use a SELECT query, then the data returned from that query will be passed to the mysql_query() function, which will in turn return it to a variable which you can specify. In the following example, two queries are made, the first does not return any data, and the second does.
Once a connection to a database has been made, you will inevitably want to perform a database query. To create a query on the selected database, we use the mysql_query() function. If you use a SELECT query, then the data returned from that query will be passed to the mysql_query() function, which will in turn return it to a variable which you can specify. In the following example, two queries are made, the first does not return any data, and the second does.


  <?
  <?
Line 47: Line 47:
  while ($row = mysql_fetch_row($result)){
  while ($row = mysql_fetch_row($result)){
     foreach ($row as $field) {
     foreach ($row as $field) {
       print "$filed . ";
       print "$field . ";
     }
     }
     print "<BR>";
     print "";
  }
  }
  ?>
  ?>