23.03.2017 Views

wilamowski-b-m-irwin-j-d-industrial-communication-systems-2011

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

62-10 Industrial Communication Systems<br />

Example 2: To display all data that is in the employeeinfo database table,<br />

mysql> SELECT * FROM employeeinfo;<br />

62.4.3.2 WHERE Clause<br />

To extract those records that fulfill specific criteria<br />

mysql> SELECT LastName, Department FROM employeeinfo WHERE<br />

Employee_ID=2;<br />

62.4.3.3 ORDER BY Keyword<br />

To sort records in the table<br />

mysql> SELECT * FROM employeeinfo ORDER BY Employee_ID DESC;<br />

To sort in ascending order, use ASC instead of DESC.<br />

62.5 Creating Dynamic Web Sites Using PHP and MySQL<br />

We are going to discuss some simple ways to create a dynamic Web site. These include connecting to<br />

the database through PHP, extracting data that sits in MySQL database, and presenting it as a part of<br />

the Web page.<br />

62.5.1 Connecting to Database<br />

To connect to a database using PHP, you do not need any other program. PHP features some built-in<br />

functions that can connect, manage and disconnect to MySQL database.<br />

Syntax:<br />

mysql_connect("localhost","username","password")<br />

Since the connection returns an identifier, we can store it in a variable for later use.<br />

Example:<br />

<br />

To display the error message when connection fails, “die” function serves that purpose.<br />

To close the connection<br />

Ex: mysql_close($con);<br />

62.5.2 SQL Queries with PHP<br />

To send SQL queries (commands) to the database and view the results of those queries<br />

Syntax:<br />

mysql_query("query", connection_id);<br />

© <strong>2011</strong> by Taylor and Francis Group, LLC

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!