Networking North Dakota Here Service Your Computer Here
AmegA Design - You Be Creative - We will help you create it! Computers For Kids North Dakota
AmegA Web Design, & Bulk Ink Systems
New and Used Computers and equipment in North Dakota Tutoring for Windows based PC's
AmegA News Letter and Information STOP BUYING EXPENSIVE INK CARTRIDGES!
Streaming Internet Communication is the Future  
  Streaming Internet Communication is the Future
 
Streaming Internet Communication is the Future

Thank You Web Monkey
http://www.webmonkey.com
I Have made a copy of these how to dues because of the awesome direction it gives for php learning

Web Monkey PHP

 


PHP
By Web Monkey

Page 6 — Pull It Back Out

--------------------------------------------------------------------------------

OK, now we've got our data in the database. Let's do something with it. Copy and paste the following into a text file and save it in your Web server document tree with a .php3 extension.


<html>

<body>

<?php

$db = mysql_connect("localhost", "root");

mysql_select_db("mydb",$db);

$result = mysql_query("SELECT * FROM employees",$db);

printf("First Name: %s<br>\n", mysql_result($result,0,"first"));

printf("Last Name: %s<br>\n", mysql_result($result,0,"last"));

printf("Address: %s<br>\n", mysql_result($result,0,"address"));

printf("Position: %s<br>\n", mysql_result($result,0,"position"));

?>

</body>

</html>


Let's explain what happens here. The mysql_connect() function opens a link to a MySQL server on the specified host (in this case it's localhost) along with a username (root). If you needed to specify a password, you'd add it here as well. The result of the connection is stored in the variable $db.

mysql_select_db() then tells PHP that any queries we make are against the mydb database. We could create multiple connections to databases on different servers. But for now, let's leave it to this.

Next, mysql_query() does all the hard work. Using the database connection identifier, it sends a line of SQL to the MySQL server to be processed. The results that are returned are stored in the variable $result.

Finally, mysql_result() is used to display the values of fields from our query. Using $result, we go to the first row, which is numbered 0, and display the value of the specified fields.

The syntax of the printf function may seem a little odd if you haven't used Perl or C before. In each of the lines above, %s indicates that the variable in the second half of the expression (e.g., mysql_result($result,0,"position")) should be treated as a string and printed. For more on printf, see the PHP documentation.

So there we have it. We successfully complied, installed, and configured MySQL and PHP, and we've executed a simple script to retrieve some information. In Lesson 2, we'll do some clever stuff to display multiple records and even send data to and from the database.

Come on back, now.




  Streaming Internet Communication is the Future
  Streaming Internet Communication is the Future
 
Streaming Internet Communication is the Future

Thank You Web Monkey
http://www.webmonkey.com
I Have made a copy of these how to dues because of the awesome direction it gives for php learning

Web Monkey PHP

 



AmegA Home 1910 E Front Ave Bismarck, ND

1910 E Front Ave - Bismarck, ND
701-223-9694
HOME * NETWORKING * SERVICE * SALES * TUTORING * WEB DESIGN * COMPUTERS FOR KIDS * NEWSLETTER * CONTINUOUS INK MACHINE SYSTEM * VIDEO EMAIL * CONTACT US HERE
Would You Like To Hear Some Silly Commercials That AmegA Has Placed On Some Cool Radio Stations Here
Bill Straily& Scott MC Gowen At Cumulus - Jason Huber & The B Man at Clear Channel
Commercials
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17