Home arrow PHP arrow Page 10 - The Soothingly Seamless Setup of Apache, SSL, MySQL, and PHP

Are PHP and MySQL Working Together? - PHP

The much anticipated update to our original article on getting Apache, MySQL, Mod_SSL, and PHP to work seamlessly with each other is finally here! Ever try to get Apache, Mod_SSL, PHP, and MySQL all working in harmony on the same box? It's a very difficult task, but article author Israel Denis Jr. has come up with detailed instructions for compiling all these and getting them working together seamlessly to make the killer server software system.

TABLE OF CONTENTS:
  1. The Soothingly Seamless Setup of Apache, SSL, MySQL, and PHP
  2. Assumptions
  3. Prerequisites
  4. How it Works
  5. Game Plan
  6. PHP Installation (*NIX)
  7. Apache
  8. Testing Our Work: Is Apache working?
  9. Is SSL Working?
  10. Are PHP and MySQL Working Together?
  11. Conclusion
By: Israel Denis Jr. and Eugene Otto
Rating: starstarstarstarstar / 41
June 07, 2000

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
Now, we can confirm that PHP is working with MySQL by creating a simple script to do some inserting and deleting of data from the "test2" database. Again this is just a simple script to see if it worked. In another article we will talk about PHP scripting to connect to a MySQL database. Remember, we already created the database and a table. We could had done it here, but chose not to. We wanted to double check that root had privileges to create DB and tables. However, PHP provides support for MySQL so we can easily write code to create a testing database and several records.

Remember, we created the "books" table prior to getting to this point. This portion will not work if you skipped prior sections. We created the "test2" database with a "books" table, and inserted a record for a book.

This script basically goes through the table and list all the fields by name. It's very simple.
<?

$dbuser = 'root';

$dbhost = 'localhost';

$dbpass = 'password';

$dbname = 'test2';

$dbtble = 'books';

$mysql_link = mysql_connect($dbhost,$dbuser,$dbpass);

$column = mysql_list_fields($dbname,$dbtble,$mysql_link);

for($i=0; $i< mysql_num_fields($column); $i++ )
{
print mysql_field_name($column,$i )."<br>";
}

?>

A more complex example will show you some of the cool features of PHP.
<html>
<head>
<title>Example 2 -- more details</title>
</head>
<body bgcolor="white">
<?

$dbuser = 'root';

$dbhost = 'localhost';

$dbpass = 'password';

$dbname = 'test2';

$dbtable = 'books';

//------ DATABASE CONNECTION --------//
$mysql_link = mysql_connect($dbhost,$dbuser,$dbpass);
$column = mysql_list_fields($dbname,$dbtable,$mysql_link);
$sql = "SELECT * FROM $dbtable";
$result = mysql_db_query($dbname,$sql);
?>
<table bgcolor="black">
<tr><td>
<table><!---- Inside Table ---->
<?
while($value = mysql_fetch_array($result))
{
print "<tr BGCOLOR=YELLOW>";
//This loop goes through the colums and prints
//each value
for($i=0; $i< mysql_num_fields($column); $i++ )
{
print "<td> $value[$i] </td>";
}
print "</tr>";
}
mysql_free_result($result);
mysql_close();
?>
</table><!---- Inside Table ----->
</td></tr>
</table>

</body>
</html>


Notice, how you can have both HTML and PHP commands inside the same file, one of the nice things about PHP scripts. Because you begin with "


 
 
>>> More PHP Articles          >>> More By Israel Denis Jr. and Eugene Otto
 

blog comments powered by Disqus
   

PHP ARTICLES

- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap

Dev Shed Tutorial Topics: