Dennis Ritchie Will Be Remembered

Last week, we heard the passing of Steve Jobs. This week, another technology icon, a lesser known one, is now gone. Dennis Ritchie, the founder the Unix operating system, as well as the founder of the C programming language has died. 

Ritchie along with Ken Thompson created the Unix operating system during their tenure at Bell Labs. Shortly after, Ritchie started working on the C programming language. His contributions to Unix and C were monumental.

I still have old C books written by Dennis and Brian Kernighan stashed in a box somewhere.
For nostalgia purposes, I should re-read those books again.

Dennis Ritchie didn’t receive the fanfare or the credit that Steve Jobs have had, but Ritchie’s impact to the tech industry will be long lasting. After all, Microsoft Windows and PHP, two technologies impacted by Ritchie’s creation, are written in C.

PHP And MSSQL

This article will show you how to connect to Microsoft’s MSSQL database via PHP. Typically, most PHP configurations involves the use of MySQL database, but every once in a while, there might be a need to connect PHP with MSSQL. So, here’s a sample script to get you started.

<?php
$sql_server = "localhost";
$sql_user   = "username";
$sql_pass   = "password";
$sql_db     = "database"; 
 
// Connect to the database
$db = mssql_connect($sql_server, $sql_user, $sql_pass)
or die("Can't connect to the MSSQL Server."); 
 
// Select a database
$select = mssql_select_db($sql_db, $db)
or die("Can't open the database " .$sql_db); 
 
// SQL statement
$query = "SELECT * FROM tablename WHERE id='3'";
 
// Execute the SQL query
$result = mssql_query($query);
 
// Display rows returned
$num_rows = mssql_num_rows($result); 
echo $num_rows." rows"; 
 
// Display results 
while($row = mssql_fetch_array($result)) {
  echo $row["id"];
  echo $row["first"];
}
 
// Close DB connection
mssql_close($db);
?>

gPHPEdit

Gnome is a desktop environment for GNU/Linux or UNIX computers. Gnome comes standard with a handy text editor called Gedit. The Gedit text editor is simple and easy to use, but it lacks the features essential to be a programming editor. Introducing gPHPEdit, a PHP, CSS and HTML development editor. It comes with syntax highlighting, coding assistance, syntax checking, code navigation and integrated help.

gPHPEdit will recognize PHP and HTML files and will color highlight the file during editing. It recognizes all PHP functions up to and including PHP 4.3.0. gPHPEdit will also recognize CSS files and will color highlight the file during editing. It highlights valid CSS classes and descriptors. gPHPEdit also recognizes SQL files and will color highlight the file during editing.

You can learn more about the features of gPHPEdit from its website.

To install gPHPEdit, simply run this command from the terminal:

# sudo apt-get install gphpedit

The only thing I found annoying at the outset was the right hand edge guide, but I was able to remove it by editing Preferences. I also activated WordWrap as a matter of preference since I don’t like using horizontal scroll bars.

PHPMailer

Have you ever tried to use the mail function in PHP and it doesn’t work? Chances are the sendmail on the host server is not configured correctly. Maybe you may need to play around with PHP.INI to make it work. There is an easy workaround to make your mail function work without tinkering with sendmail. Try PHPMailer.

PHPMailer is a PHP class for PHP (www.php.net) that provides a package of functions to send email. The two primary features are sending HTML Email and e-mails with attachments. PHPMailer supports nearly all possiblities to send email: mail(), Sendmail, qmail & direct to SMTP server. You can use any feature of SMTP-based e-mail, multiple recepients via to, CC, BCC, etc. In short: PHPMailer is an efficient way to send e-mail within PHP.

The key feature of PHPMailer is having the ability to use the mail function with a smtp server. There several features worth noting such as the ability to send an HTML email, CC and BCC recipients, embedded images, attachments, custom mail headers, redundant SMTP servers, SMTP authentication, wordwrap, etc.

A sample PHP mail function may look like this:

$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
           'Reply-To: webmaster@example.com' . "\r\n" .
mail($to, $subject, $message, $headers);

In PHPMailer, you would write something like this using SMTP server:

require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.host.com";
$mail->From = "donotreply@host.com";
$mail->FromName = "Your name";
$mail->AddAddress("someone@domain.com", "John Doe");
$mail->Subject = "Hello there";
$mail->Body = "Hi, just wanted to drop by and say hi." ;
if(!$mail->Send()) {
  echo "Message could not be sent.";
} else {
  echo "Message successful";
}

Some smtp servers may require authentication. You may need to add these lines:

$mail->SMTPAuth = true;
$mail->Username = "username";
$mail->Password = "password";

PHPMailer is an excellent and simple replacement for the PHP mail function. It’s easy and it works. Give PHPMailer a try.

CSS Class vs ID

When I first learned CSS, the biggest challenge for me was learning the difference between “ID” and “CLASS” selectors. I struggled with the concept until I learned that “ID” selectors are unique and can only be used once in a page layout. On the other hand, “CLASS” selectors can occur multiple times in a single page layout. A good example of using the “CLASS” selector is using it for posts or articles which can occur many times in a single page. See some examples below.

ID Selectors

ID selectors are unique. They occur only once in a page layout. A good use for an ID selector are headers, footers, menus, sidebars, etc. Remember, it’s must be unique and can NOT be repeated in a page.

<div id="header">
header info here
</div>

Apply CSS to ID selectors by using the # pound sign. I associate “ID” selectors to an ID Card or a Drivers License which contains a unique number. Therefore IDs have unique numbers and uses the # pound sign.

#header {
padding: 10px;
margin: 2px;
}
#footer {
color: #555;
font-size: 12px;
}

CLASS selectors

CLASS selectors on the other hand, occur multiple times in a page such as divs for posts, articles, etc.

<div class="content">
content here....
</div>
<div class="content">
content here....
</div>

Apply CSS to CLASS selectors by using the . period sign. I associate CLASS selectors to a “class period” like in a school enviroment — a class period. The CSS code under .post in this case will apply to every instance of the CLASS selector.

.post {
padding: 10px;
margin: 2px;
}

I hope this short article clears up some of the confusion between ID and CLASSES for first time CSS coders. I hope it gives you a much clearer picture as to which selectors to use when designing your next page layout.