Monday, February 4, 2013

Setting Up Virtual Hosts for XAMPP


Virtual Hosts

Virtual Hosts give you the ability to "host" more than one Web site and domain on your computer. With a virtual host you can have separate local domain names for each of your Web sites: for example, http://clientA/ for one site and http://clientB/ for another. When you type the URL for the Virtual Host in your Web browser, the browser doesn’t go out onto the internet to find the site, but instead asks for the proper file from the Web server running on your computer. Not only does a Virtual Host let you run multiple Web sites on your computer, but it also lets you store the files for those sites anywhere on your computer and not just in the C:\XAMPP\htdocs folder.
Adding a Virtual Host is a 2-step process:
  1. Add a new entry to your computer’s hosts file.
    hosts file can be used to point requests for a domain to a particular IP addressin other words, it lets you re-direct communications to a particular domain. In the case of a virtual host, it can tell the computer to NOT go out on the internet when you type a particular URL like http://clientA/, but instead look for that particular domain on your own computer.
  2. Edit the Apache configuration file to accept Virtual Hosts and define the particular Virtual Hosts you want to setup on your computer.
    The first step above, merely redirects requests from a particular domain to your computer, but this step prepares the Web server on your computer for handling those requests. In this step, you not only provide the name of the Virtual Host, but also tell Apache where the files for the site are located on your computer.

Detailed Steps

  1. Launch Notepad and open the hosts file located at C:\windows\system32\drivers\etc\hosts. (You may not be able to see the windows folder–some files are hidden by default under Windows. Here are instructions to make those files visible.)
    On Vista, you’ll also need to have access to change the hosts file. To do that, launch Notepad by right clicking on Notepad from the Start menu and choosing "Run As Administrator." This will give you permission to edit and save the file.
  2. At the end of that file type:
    127.0.0.1      clientA.local
    127.0.0.1 is how a computer refers to itself—it’s an IP address that points back to the computer, kind of like a computer’s way of saying "ME." The second part (clientA.local) is the "domain" of the virtual host. To visit this domain in a Web browser you’d type http://clientA.local. You don’t have to add the .local part to the hosts files—you could just as easily add 127.0.0.1 clientA and access the site in your Web browser withhttp://clientA—but I find it helpful for differentiating between a real Web site out on the Internet like clientA.com, and the test sites I have running on my own computer.
  3. Save and close the hosts file.
    That finishes the first part of this task. You’ve prepared your computer to handle requests to http://clientA.local. Now you need to tell the Web server, Apache, how to handle those requests.
  4. In Notepad open the Apache configuration file located at C:\xampp\apache\conf\extra\httpd-vhosts.conf
  5. At the bottom of that file add:
    NameVirtualHost *
      
        DocumentRoot "C:\xampp\htdocs"
        ServerName localhost
      
      
        DocumentRoot "C:\Documents and Settings\Me\My Documents\clientA\website"
        ServerName clientA.local
      
        Order allow,deny
        Allow from all
      
    
      
    The first five lines of code turn on the Virtual Host feature on Apache, and set up the C:\xampp\htdocs folder as the default location for http://localhost. That’s important since you need to be able to access the XAMPP web pages at http://localhost/ so that you can use PHPMyAdmin.
    The stuff in yellow represents a single Virtual Host. You’ll add one chunk of code just like this for each Virtual Host (or Web site) on your computer
    You’ll need to modify the stuff highlighted in blue. The first item — DocumentRoot — indicates where the files for this site are located on your computer. The second part–ServerName — is the name you provided in step 2 above: the virtual host name. For example, clientA.local. The third item — the part — is the same path you provided for the DocumentRoot. This is required to let your Web browser have clearance to access these files.
  6. Save and close the Apache configuration file, and restart Apache from the XAMPP control panel.
  7. Start a Web browser and type a URL for the virtual host. For example: http://clientA.local/.
    You should now see the home page for your site.

Wednesday, July 4, 2012

Importing Excel files into MySQL with PHP

If you have Excel files that need to be imported into MySQL, you can import them easily with PHP. First, you will need to download some prerequisites:
PHPExcelReader - http://sourceforge.net/projects/phpexcelreader/
Spreadsheet_Excel_Writer - http://pear.php.net/package/Spreadsheet_Excel_Writer
Once you've downloaded both items, upload them to your server. Your directory listing on your server should have two directories: Excel (from PHPExcelReader) and Spreadsheet_Excel_Writer-x.x.x (from Spreadsheet_Excel_Writer). To work around a bug in PHPExcelReader, copy oleread.inc from the Excel directory into a new path:
Spreadsheet/Excel/Reader/OLERead.php
The PHPExcelReader code will expect OLERead.php to be in that specific location. Once that is complete, you're ready to use the PHPExcelReader class. I made an example Excel spreadsheet like this:
Name                Extension   Email
----------------------------------------------------
Jon Smith           2001        jsmith@domain.com
Clint Jones         2002        cjones@domain.com
Frank Peterson      2003        fpeterson@domain.com
After that, I created a PHP script to pick up the data and insert it into the database, row by row:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
require_once 'Excel/reader.php';
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('CP1251');
$data->read('exceltestsheet.xls');
 
$conn = mysql_connect("hostname","username","password");
mysql_select_db("database",$conn);
 
for ($x = 2; $x < = count($data->sheets[0]["cells"]); $x++) {
    $name = $data->sheets[0]["cells"][$x][1];
    $extension = $data->sheets[0]["cells"][$x][2];
    $email = $data->sheets[0]["cells"][$x][3];
    $sql = "INSERT INTO mytable (name,extension,email) 
        VALUES ('$name',$extension,'$email')";
    echo $sql."\n";
    mysql_query($sql);
}
 
After the script ran, each row had been added to the database table successfully. If you have additional columns to insert, just repeat these lines, using an appropriate variable for each column:
$variable = $data->sheets[0]["cells"][$row_number][$column_number];

Monday, January 31, 2011

Nice ones!!!

Lesson 1:

A man is getting into the shower just as his wife is finishing up her shower, when the doorbell rings.

The wife quickly wraps herself in a towel and runs downstairs.

When she opens the door, there stands Bob, the next-door neighbor.

Before she says a word, Bob says, ‘I’ll give you $800 to drop that towel.’

After thinking for a moment, the woman drops her towel and stands naked in front of Bob, after a few seconds, Bob hands her $800 and leaves.

The woman wraps back up in the towel and goes back upstairs.

When she gets to the bathroom, her husband asks, ‘Who was that?’

‘It was Bob the next door neighbor,’ she replies.

‘Great,’ the husband says, ‘did he say anything about the $800 he owes me?’



Moral of the story:

If you share critical information pertaining to credit and risk with your shareholders in time, you may be in a position to prevent avoidable exposure.



Lesson 2:

A priest offered a Nun a lift.

She got in and crossed her legs, forcing her gown to reveal a leg.

The priest nearly had an accident.

After controlling the car, he stealthily slid his hand up her leg.

The nun said, ‘Father, remember Psalm 129?’

The priest removed his hand. But, changing gears, he let his hand slide up her leg again.
The nun once again said, ‘Father, remember Psalm 129?’

The priest apologized ‘Sorry sister but the flesh is weak.’

Arriving at the convent, the nun sighed heavily and went on her way.

On his arrival at the church, the priest rushed to look up Psalm 129. It said, ‘Go forth and seek, further up, you will find glory.’

Moral of the story:
If you are not well informed in your job, you might miss a great opportunity.



Lesson 3:

A sales rep, an administration clerk, and the manager are walking to lunch when they find an antique oil lamp.

They rub it and a Genie comes out.
The Genie says, ‘I’ll give each of you just one wish.’
‘Me first! Me first!’ says the admin clerk. ‘I want to be in the Bahamas , driving a speedboat, without a care in the world.’
Puff! She’s gone.

‘Me next! Me next!’ says the sales rep. ‘I want to be in Hawaii , relaxing on the beach with my personal masseuse, an endless supply of Pina Coladas and the love of my life.’

Puff! He’s gone.

‘OK, you’re up,’ the Genie says to the manager.
The manager says, ‘I want those two back in the office after lunch.’

Moral of the story:
Always let your boss have the first say.

Lesson 4

An eagle was sitting on a tree resting, doing nothing.

A small rabbit saw the eagle and asked him, ‘Can I also sit like you and do nothing?’
The eagle answered: ‘Sure, why not.’

So, the rabbit sat on the ground below the eagle and rested. All of a sudden, a fox appeared, jumped on the rabbit and ate it.

Moral of the story:
To be sitting and doing nothing, you must be sitting very, very high up.



Lesson 5

A turkey was chatting with a bull.

‘I would love to be able to get to the top of that tree’ sighed the turkey, ‘but I haven’t got the energy.’
‘Well, why don’t you nibble on some of my droppings?’ rep lied the bull. They’re packed with nutrients.’

The turkey pecked at a lump of dung, and found it actually gave him enough strength to reach the lowest branch of the tree.

The next day, after eating some more dung, he reached the second branch.

Finally after a fourth night, the turkey was proudly perched at the top of the tree.

He was promptly spotted by a farmer, who shot him out of the tree.

Moral of the story:
Bull Shit might get you to the top, but it won’t keep you there..



Lesson 6

A little bird was flying south for the winter. It was so cold the bird froze and fell to the ground into a large field.

While he was lying there, a cow came by and dropped some dung on him.

As the frozen bi rd lay there in the pile of cow dung, he began to realize how warm he was.

The dung was actually thawing him out!
He lay there all warm and happy, and soon began to sing for joy.
A passing cat heard the bird singing and came to investigate.

Following the sound, the cat discovered the bird under the pile of cow dung, and promptly dug him out and ate him.

Morals of the story:
(1) Not everyone who shits on you is your enemy.

(2) Not everyone who gets you out of shit is your friend.

(3) And when you’re in deep shit, it’s best to keep your mouth shut!

Wednesday, August 25, 2010

Import Microsoft Access (v2003) tables into SQL Server Express Edition (v2005)

In my little corner of the world, I have seen this issue come up three times by three different people in the past 7 days so I thought I would posts this. I actually just went through this myself a little bit ago:

1. Open Microsoft SQL Server Management Studio Express
2. Create a database for the import, if necessary
3. Open the Microsoft Access database that will be imported into SQL
4. Switch to “Tables” in Microsoft Access
5. Right click on the Table to be exported
6. Select “Export”
7. In the ‘Save Type As…’ field select “ODB Databases()”
8. Name the Table and Press “OK”
9. Press the “New…” button
10. Select “SQL Server” and Press “Next>”
11. Enter a name for the Data Source then Press “Next>”
12. Press “Finish”
13. Enter a Description if necessary
14. Select the SQL Server to connect to and Press “Next>”
15. Select the correct Authentication settings and Press “Next>”
16. Check “Change the default database to:” and Select the correct Database then Press “Next>”
17. Press “Finish”
18. Press “Test Data Source…” to very the information entered was correct
19. If test completed successfully then Press “OK”
20. Press “OK”
21. In “SQL Server Login” dialog box, enter correct authentication information and Press “OK”
22. Export should occur without any further dialog boxes or prompts
23. Switch back to the Microsoft SQL Server Management Studio Express
24. Navigate to the database, refresh the console and verify the table was created/imported

Wednesday, March 10, 2010

creating MYSQL stored procedure and calling it from PHP

# Open phpMyadmin.
# Select a database to work with.
# Open the SQL tab.

Assume your database contains table called employees.

In the SQL tab,
you can start writing :

DROP PROCEDURE IF EXISTS listEmployees $$
CREATE PROCEDURE listEmployees()
BEGIN
select * from employees;
END $$

In delimiter [;] change ; to $$.

Hit go. Thats it, you are done with creating your first stored procedure.



Up to this anyone can google and create the stored procedure, but big mess is how to use this in PHP.
After many trails and trails I learned how to call procedure in php.


Normally you would use the below to connect to a mysql database in php.
$connector=mysql_connect(host,user,pass);

In order to use stored procedures try connecting like this:

$connector=mysql_connect(host,user,pass,true,65536);
mysql_select_db(database,$connector); //Nothing changes here

Now you are done with making php mysql to use with stored procedure.

Lets see how you can call stored procedure with php.

$query=mysql_query("CALL listEmployees()");
while($result=mysql_fetch_array($query))
{
echo $result[emp_name]."
";
}

Thats it. It calls procedure called listEmployees(which we written above and that does lists all employees data from employee table).

Writing stored procedures of mysql in PHPMYADMIN

1. Open phpMyadmin.
2. Select a database to work with.
3. Open the SQL tab.
4. Select all of the SQL statements between the DELIMITER statements in your stored procedure script. Do not include the DELIMITER statements! Here’s what my example script should look like:

DROP PROCEDURE IF EXISTS spFoo $$
CREATE PROCEDURE spFoo ()
BEGIN
SELECT 'Foo' FROM DUAL;
END $$

5. In the delimiter field, just below the SQL editor’s text area, enter $$ as your delimiter.

Saturday, January 23, 2010

Famous quotes, witty quotes, and funny quotations 2



"I find that the harder I work, the more luck I seem to
have."
- Thomas Jefferson (1743-1826)



"Each problem that I solved became a rule which served
afterwards to solve other problems."
- Rene Descartes
(1596-1650), "Discours de la Methode"



"In the End, we will remember not the words of our enemies,
but the silence of our friends."
- Martin Luther King Jr. (1929-1968)


"Whether you think that you can, or that you can't, you are usually right."
- Henry Ford (1863-1947)


"Do, or do not. There is no 'try'."
- Yoda ('The Empire Strikes Back')


"The only way to get rid of a temptation is to yield to it."
- Oscar Wilde (1854-1900)


"Don't stay in bed, unless you can make money in bed."
- George Burns (1896-1996)




"I don't know why we are here, but I'm pretty sure that it is not in order to enjoy ourselves."
- Ludwig Wittgenstein (1889-1951)




"There are no facts, only interpretations."
- Friedrich Nietzsche (1844-1900)




"Nothing in the world is more dangerous than sincere ignorance and conscientious stupidity."
- Martin Luther King Jr. (1929-1968)



"The use of COBOL cripples the mind; its teaching should, therefore, be regarded as a criminal offense."
- Edsgar Dijkstra (1930-2002)




"C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg."
- Bjarne Stroustrup




"A mathematician is a device for turning coffee into theorems."
- Paul Erdos (1913-1996)




"Problems worthy of attack prove their worth by fighting back."
- Paul Erdos (1913-1996)




"Try to learn something about everything and everything about something."
- Thomas Henry Huxley (1825-1895)



"Dancing is silent poetry."
- Simonides (556-468bc)




"The only difference between me and a madman is that I'm not mad."
- Salvador Dali (1904-1989)




"If you can't get rid of the skeleton in your closet, you'd best teach it to dance."
- George Bernard Shaw (1856-1950)




"But at my back I always hear Time's winged chariot hurrying near."
- Andrew Marvell (1621-1678)




"Good people do not need laws to tell them to act responsibly, while bad people will find a way around the laws."
- Plato (427-347 B.C.)




"The power of accurate observation is frequently called cynicism by those who don't have it."
- George Bernard Shaw (1856-1950)




"Whenever I climb I am followed by a dog called 'Ego'."
- Friedrich Nietzsche (1844-1900)




"Everybody pities the weak; jealousy you have to earn."
- Arnold Schwarzenegger (1947-)




"Against stupidity, the gods themselves contend in vain."
- Friedrich von Schiller (1759-1805)



"We have art to save ourselves from the truth."
- Friedrich Nietzsche (1844-1900)




"Never interrupt your enemy when he is making a mistake."
- Napoleon Bonaparte (1769-1821)




"I think 'Hail to the Chief' has a nice ring to it."
- John F. Kennedy (1917-1963) when asked what is his favorite song




"I have nothing to declare except my genius."
- Oscar Wilde (1854-1900) upon arriving at U.S. customs 1882




"Human history becomes more and more a race between education and catastrophe."
- H. G. Wells (1866-1946)




"Talent does what it can; genius does what it must."
- Edward George Bulwer-Lytton (1803-1873)





"The difference between 'involvement' and 'commitment' is like an eggs-and-ham breakfast: the chicken was 'involved' - the pig was 'committed'."
- unknown




"Women might be able to fake orgasms. But men can fake a whole relationship."
- Sharon Stone




"If you are going through hell, keep going."
- Sir Winston Churchill (1874-1965)



"He who has a 'why' to live, can bear with almost any 'how'."
- Friedrich Nietzsche (1844-1900)




"Many wealthy people are little more than janitors of their possessions."
- Frank Lloyd Wright (1868-1959)