Ulyssesonline

the tech surfer

  • Home
  • About
  • Archives
You are here: Home / 2011 / Archives for August 2011

Archives for August 2011

August 31, 2011

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);
?>

<?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); ?>

Filed Under: General, Linux, PHP Tagged With: microsoft, mssql, PHP, Programming

August 30, 2011

Fix Virtualbox After Kernel Upgrade

Fix Virtualbox After Kernel Upgrade

Ubuntu 11.04 recently upgraded to Linux kernel 2.6.38-11. Unfortunately, every new Linux kernel introduced on your system will break your Virtualbox setup. This article will show you how to fix Virtualbox with a new kernel. The error will appear if you try to launch a Virtual Machine. You will most likely get the following errors:

As detailed in the error box, you will need to run vboxdrv setup to fix the problem. All you need to do is open up the Terminal and type this command:

$ sudo /etc/init.d/vboxdrv setup

As displayed in the Terminal, the vboxdrv setup will stop the current Virtualbox kernel module, uninstall it, register a new kernel module, and finally start it. This completes the Virtualbox upgrade that’s necessary after each Linux kernel upgrade.

So, in the future, if your Ubuntu distro upgrades to a newer Linux kernel, you know exactly what to do to make your Virtualbox work with the latest kernel.

Filed Under: General, Linux Tagged With: kernel, Linux, ubuntu, upgrade, virtualbox

August 30, 2011

Validate Email Addresses

Here’s one way to validate email addresses using the regular expression I found online that works great for me. You can use this little piece of PHP code in your forms or just about any place you need it. The regular expression should be typed in one continuous line, but I added a couple of line breaks for legibility purposes, in this example. You can also place this code  inside a function, so you can use it repeatedly by simply calling the function, in this case, validate_email(). If you have a better regular expression for validating email addresses, please share.

The Code

if (!eregi("
  ^[_a-z0-9-]+(\.[_a-z0-9-]+)*
  @[a-z0-9-]+(\.[a-z0-9-]+)*
  (\.[a-z]{2,3})$", $email)):
 echo "Invalid email.";
else:
 echo "Valid Email.";
endif;

The Function

function validate_email($email) {
 if (!eregi("
   ^[_a-z0-9-]+(\.[_a-z0-9-]+)*
   @[a-z0-9-]+(\.[a-z0-9-]+)*
   (\.[a-z]{2,3})$", $email)):
  echo "Invalid email.";
 else:
  echo "Valid Email.";
 endif;
}

Filed Under: General Tagged With: forms, PHP, validate email

  • 1
  • 2
  • 3
  • …
  • 7
  • Next Page »

Copyright © 2003 - 2018