Business Building Tips for Entrepreneurs

0

Category:

As a business owner, you already know that people buy for emotional reasons. No matter how great your product or service is, apathetic consumers will simply dismiss it. You need to tap into their emotions if you're going to convince them that they need your product.

By manipulating the pleasure and pain triggers in your prospect, you will be catching their attention, and encouraging them to act (either to rid themselves of the pain, or to retain feelings of pleasure.)

Here are some tips for injecting pain and pleasure into your marketing messages:

Tell stories- people immediately connect with stories. If your story relates to an experience your prospect has had, they will immediately be reminded of the feelings they are fighting to avoid, or the feelings they'd love to feel again.

Make your prospect imagine- the mind is a powerful tool. Asking your prospect to visualize sets a stage for you to present painful / pleasurable situations. Tap into past experiences, or create hypothetical ones. When it comes to emotion, your prospect's brain will not make a distinction between fact and fiction.

Be confident in your product- when talking about your product or service, don't say what it might or could do for them. Explain what it will do. (Remember, your prospect needs to get rid of their pain or acquire pleasure as soon as possible. They need a guaranteed solution!)

Use the right words- make your message vibrant by using active verbs (example: Jane runs instead of Jane is running.) Also, use words associated with pleasure (babies, soft, relaxing etc.) or pain (dentist, suffering, trauma).

One last point: once you draw out the pain or pleasure, let your audience revel in it. Don't be too quick to move past the emotion. It's the emotion that moves people to action. If you can successfully incorporate emotional stimulation in your marketing messages, you will be transporting your prospect to a buying state!

Must Do Twitter SEO Tips

0

Category:

I think it is crazy when I come across a Twitter account that doesn’t have a bio section filled in or even a URL in the domain section. How can you forget to put your website domain in your profile? Here are some ways to really keep your SEO elements moving in the right direction with your Twitter account.


Here are some of the top must do Twitter SEO tips to consider:

URL: Probably the most important thing. Don’t forget to have your URL visible in your profile. It only takes a few seconds to type in.

User Name: Your user name is also going to be listed in your domain so chose one wisely. If you pick something to cutesy you will have no chance of ranking in search results for your targeted keywords.

Description: Your description is used as the meta tag information for your profile so you can see where this would come in very handy to have optimized for your targeted keywords. Are you starting to see the overall goal of optimizing your profile?


Background: Take advantage of using your background to get more of your messaging across. You are allowed to upload your own background image so use it to either further your business brand or you can use the right hand side of the background to list some information about your services or your business.



Personality: Don’t let your profile seem like just a business even though you might be there to generate new leads. Try adding some personality to your profile. Ask your followers questions, have a contest show your audience that there is a human being behind that Twitter profile.



Hash Tags: This one is often overlooked by many people. If you drop a “#” before a word like SEO or any other keyword you might be targeting this will allow your tweet to show up in search results for when others search for that keyword.



Whenever dealing with any online social network or even a business profile optimization and SEO elements are very important. It doesn’t mean that it will rank all the time but if you are spending the time to create a profile you might as well make it 100% efficient in order to increase the possibilities of that profile ranking in search results.

Time To Break Your Old Marketing Habits

0

Category:

Are you used to doing things a certain way and can’t seem to break the habit? Old habits are hard to break which is why internet marketing can be tough if you do not evolve with the rest of the industry. You might have started doing things a certain way years ago, and found that they just don’t seem to work the same way they once did. That is not a coincidence that is actually the industry moving past you while you fail to evolve.
Consider changing things up in order to grow and evolve:


Approach: If something works online than great, but if it doesn’t work than you need to fix it. Marketing your business online is not the same as it was 3 years ago. Things change and you need to evolve with your approach otherwise you run the risk of cutting your audience short.

Brand: Is your online brand stale? Have you not rebranded your business since the day you started it? Branding online in today’s marketplace is very important. Customers really focus on brand recognition before they make purchases online and a stale non branded marketing approach online could work against any new potential sales.

Website: Consult a professional about your website if you haven’t touched it in five years. You might think it’s the cat’s bag but your audience might be seriously turned off by your website. Don’t outdate yourself by not updating your website. Design is very subjective but good design with strong conversion aspects is always going to be important. Don’t be stubborn about your website design and consult with someone who understands good business web design. It is more than just making things look appealing for your audience. It is all about leading your audience down a path. That path could be the messaging of your brand or leading them down the path to a website conversion.

The internet marketing space is not an area where you can get comfortable and set in your ways. Failure to evolve will result in brand death and in today’s marketplace you have to do everything you can in order to really stand out.

Trust Is Now More Important Than Ever

0

Category:

Everything online revolves around trust. It is not talked about that often but trust works on both sides of the spectrum. Your website visitors need trust in order to make any sort of contact with your business website and the search engines need to trust you in order to label you as an authority figure in the search engines. There are many ways to develop trust but it truly takes time. There is no cutting corners when developing your trust factor it just sort of happens over time as a business owner.

Age: As you spend a great deal of time in the search engines you can naturally start to build up your trust factor in the eyes of your audience and the search engines. Age shows stability in the eyes of the search engines.


Linking: When industry leading resources start to quote and link to your website you start to develop trust in the eyes of the audience reading that resource and also the search engines. If you are not a worthy business an industry leading resource will not use you to quote on their website.

Branding: This could work both ways but more so for your audience. Position yourself as a strong brand and over time people will look at you as an industry leading brand. A brand instantly builds trust in the eyes of your audience and customer. A fly by night will not spend the time to really build a brand online so make an effort to build up your appearance online.

Under Promise Over Deliver: This is a very old business slogan but when done correctly utilizing this mind set will increase your trust factor. Don’t over promise and not follow through because for the long term this will not help you in building and growing your online trust.

Build Relationships: Relationship building and trust go hand in hand. Try building relationships in almost any situation you find yourself in. A relationship with the right client or person of interest could lead to significant online activities. When others in your industry start to recommend you or your services in the online space you naturally build up your trust in many ways.

Trust has become a very important attribute to strive for as a business. Trust is what gets other people inquiring and wanting to learn more about your business. It allows for a much smoother sales cycle and process. It is something that is very important for businesses to want to achieve for their own business in order to make things that much more efficient.

To Advertise - not to Advertise.

0

Category:

Have you ever heard the saying, "I know that I waste half of my advertising budget. The problem is I don't know which half!" It is this very philosophy that is prompting me to strongly inform you... advertising doesn't work! Let me show you why:

  • There is no way to track effectiveness (or ineffectiveness)
  • It's impersonal
  • The target audience is too large
  • It's costly to redo or improve
  • There is no call to action
What surprises me is the number of small business owners that save their marketing dollars just to waste them on ineffective advertising. Then, they complain because nothing is working and they don't have any customers.
I know what you're thinking, "Isn't advertising and marketing the same thing?" Well, not really. Let me explain the differences. Advertising includes: commercials, billboards, radio, and newspapers. Marketing includes: emails, letters, postcards, and fax.
So how is follow-up marketing better than advertising?
  • You can track response rates
  • You can quickly change campaigns that aren't working
  • You can specifically target your audience
  • It leads prospects to an immediate sell
If you really want to attract more customers, you will learn to market and leave the advertising to those gazillion dollar companies.

Things you must know about your customers

0

Category:

Here are the 7 things you must know about your customers:

1. Their Name- Nothing speaks to an individual faster than their first name. Use it to build your relationship with your customer.

2. What They've Purchased- If you know what your customers purchased in the past, you have a good idea what they will buy again. (And won't waste your time promoting products of little to no interest.)

3. How Often They Purchase- Individuals who buy rarely from you may need additional encouragement‌more marketing. Whereas, consistent customers may not need extra sales pitches, but might benefit from a newsletter or coupon.

4. How Much They Spend (on average)- Why spend precious time pitching products to customers that they can't afford? It might embarrass your customer, shows your lack of personal interest, and may cause customers to lose interest.

5. The Last Time They Purchased- Have you lost a customer without even knowing it? Who's still loyal? Who has strayed (and needs to be brought back)?

6. Each Interaction You've Had With Them- Documentation is important for obvious reasons. But being able to "recall" previous conversations will make your customer feel important and appreciated.

7. How They Feel About Your Business- Feedback from your customers is the best way to improve your products/services, meet your customers needs, and attract more customers.

Note: Remembering each of your customers and all of these details about them is impossible. Be sure to keep an accurate database that can easily store and retrieve this information for you--and make you look like a star to your customers!

Your Attitude effects your customers

0

Category:


Find Your Passion.

Running a business is tiring, time-consuming, and often frustrating. It's not uncommon for the "Entrepreneurial Light" to burn out. However, if you're not excited about your products or services, no one else is going to be. And, who wants to buy a product/service they're not enthusiastic about?

Quick tips for regaining your passion:

  • Write down all the reasons you love your products or services
  • Tell others the story of why you became an entrepreneur
  • Imagine what you want your business to look like in 5 years (even if it's unrealistic... perhaps especially if it's unrealistic!)
  • Read inspirational books, blogs, and articles about small business ownership
  • Take time to rejuvenate
Look, you became an entrepreneur for a reason. And, how you feel about your company is going to be reflected in the risks you'll take, the way you interact with your customers, and the amount of money you bring in!

Ray Kroc (founder of McDonald's) said, "If you work just for the money, you'll never make it, but if you love what you're doing, and always put the customer first, success will be yours."

Be passionate! Be excited! Learn to love your business, your customers, and the simple joys of small business ownership. Pass that passion on to your employees and customers, and you'll see a phenomenal difference in the growth and success of your business!

PHP - Functions, how to write functions using PHP ?

0

Category:

Creating Your First PHP Function


When you create a function, you first need to give it a name, like myCompanyMotto.
It's with this function name that you will be able to call upon your function, so make it easy to type and understand.

The actual syntax for creating a function is pretty self-explanatory, but you can be the judge of that.
First, you must tell PHP that you want to create a function. You do this by typing the keyword function followed
by your function name and some other stuff (which we'll talk about later).

Here is how you would make a function called myCompanyMotto. Note: We still have
to fill in the code for myCompanyMotto.


PHP Code:

<?php
function myCompanyMotto(){
}
?>

Note: Your function name can start with a letter or underscore "_", but not a number!

With a properly formatted function in place, we can now fill in the code that we want our
function to execute. Do you see the curly braces in the above example "{ }"? These braces define
where our function's code goes. The opening curly brace "{" tells php that the function's code is starting and a closing
curly brace "}" tells PHP that our function is done!

We want our function to print out the company motto each time it's called, so that sounds like it's a job for the echo command!


PHP Code:

<?php
function myCompanyMotto(){
    echo "We deliver quantity, not quality!<br />";
}
?>

That's it! You have written your first PHP function from scratch! Notice that the code that appears within a function is just the same as any other PHP code.

Using Your PHP Function

Now that you have completed coding your PHP function, it's time to put it through a test run. Below
is a simple PHP script. Let's do two things: add the function code to it and use the function twice.

PHP Code:

<?php
echo "Welcome to Tizag.com <br />";
echo "Well, thanks for stopping by! <br />";
echo "and remember... <br />";
?>


PHP Code with Function:

<?php
function myCompanyMotto(){
    echo "We deliver quantity, not quality!<br />";
}
echo "Welcome to Tizag.com <br />";
myCompanyMotto();
echo "Well, thanks for stopping by! <br />";
echo "and remember... <br />";

myCompanyMotto();
?>

Display:

Welcome to Tizag.com

We deliver quantity, not quality!

Well, thanks for stopping by!

and remember...

We deliver quantity, not quality!



Although this was a simple example, it's important to understand that there
is a lot going on and there are a lot of areas to make errors. When you are creating a function, follow
these simple guidelines:

  • Always start your function with the keyword function
  • Remember that your function's code must be between the "{" and the "}"
  • When you are using your function, be sure you spell the function name correctly
  • Don't give up!

PHP Functions - Parameters

Another useful thing about functions is that you can send them information that
the function can then use. Our first function myCompanyMotto isn't all that
useful because all it does, and ever will do, is print out a single, unchanging string.

However, if we were to use parameters, then we would be able to add some extra functionality!
A parameter appears with the parentheses "( )" and looks just like a normal PHP variable.
Let's create a new function that creates a custom greeting based off of a person's name.

Our parameter will be the person's name and our function will concatenate this
name onto a greeting string. Here's what the code would look like.

PHP Code with Function:

<?php
function myGreeting($firstName){
    echo "Hello there ". $firstName . "!<br />";
}
?>


When we use our myGreeting function we have to send it a string containing someone's name, otherwise
it will break. When you add parameters, you also add more responsibility to you, the programmer!
Let's call our new function a few times with some common first names.

PHP Code:

<?php
function myGreeting($firstName){
    echo "Hello there ". $firstName . "!<br />";
}
myGreeting("Jack");
myGreeting("Ahmed");
myGreeting("Julie");
myGreeting("Charles");
?>

Display:


Hello there Jack!

Hello there Ahmed!

Hello there Julie!

Hello there Charles!

It is also possible to have multiple parameters in a function. To separate multiple parameters
PHP uses a comma ",". Let's modify our function to also include last names.

PHP Code:

<?php
function myGreeting($firstName, $lastName){
    echo "Hello there ". $firstName ." ". $lastName ."!<br />";
}
myGreeting("Jack", "Black");
myGreeting("Ahmed", "Zewail");
myGreeting("Julie", "Roberts");
myGreeting("Charles", "Schwab");
?>


Display:

Hello there Jack Black!

Hello there Ahmed Zewail!

Hello there Julie Roberts!

Hello there Charles Schwab!

PHP Functions - Returning Values

Besides being able to pass functions information, you can also have them return a value.
However, a function can only return one thing, although that thing can be any integer, float, array, string, etc. that you choose!

How does it return a value though? Well, when the function is used and finishes executing, it sort of changes from being a function name into being a value. To capture this value you can set a variable equal to the function. Something like:


  • $myVar = somefunction();

Let's demonstrate this returning of a value by using a simple function that returns the sum of two integers.

PHP Code:

<?php
function mySum($numX, $numY){
    $total = $numX + $numY;
    return $total; 
}
$myNumber = 0;

echo "Before the function, myNumber = ". $myNumber ."<br />";
$myNumber = mySum(3, 4); // Store the result of mySum in $myNumber
echo "After the function, myNumber = " . $myNumber ."<br />";
?>

Display:

Before the function, myNumber = 0

After the function, myNumber = 7

When we first print out the value of $myNumber it is still set to the original value of 0.
However, when we set $myNumber equal to the function mySum, $myNumber
is set equal to mySum's result. In this case, the result was 3 + 4 = 7, which was successfully
stored into $myNumber and displayed in the second echo statement!

Using PHP With HTML Forms

0

Category:

Imagine we are an art supply store thatsells brushes, paint, and erasers. To gather order information from our prospective customers we will have to make a page with an HTML form to gather the customer's order.

Note: This is an oversimplified example to educate you how to use PHP to process HTML form information. This example is not intended nor advised to be used on a real business website.

Creating the HTML Form

If you need a refresher on how to properly make an HTML form,
check out the HTML Form
Lesson
before continuing on.

We first create an HTML form that will let our customer choose  what they would like to purchase. This file should be saved as "order.html"
.

order.html Code:

<html><body>
<h4>Tizag Art Supply Order Form</h4>
<form> 
<select> 
<option>Paint</option>

<option>Brushes</option>
<option>Erasers</option>
</select>
Quantity: <input type="text" /> 
<input type="submit" />
</form>

</body></html>

Display:

Tizag Art Supply Order Form


Quantity:

Remember to review HTML Forms
if you do not understand any of the above HTML code. Next we must alter our HTML form to specify the PHP page we wish to send this information to. Also, we set the method to "post".

order.html Code:

<html><body>

<h4>Tizag Art Supply Order Form</h4>
<form action="process.php" method="post"> 
<select name="item"> 
<option>Paint</option>
<option>Brushes</option>

<option>Erasers</option>
</select>
Quantity: <input name="quantity" type="text" /> 
<input type="submit" />
</form>
</body></html>


Now that our "order.html" is complete, let us continue on and create the "process.php" file which will process the HTML form information.

PHP Form Processor

We want to get the "item" and "quantity" inputs that we have specified
in our HTML form. Using an associative array (this term is explained in the array lesson),
we can get this information from the $_POST associative array.

The proper way to get this information would be to create two new variables, $item
and $quantity and set them equal to the values that have been "posted". The name
of this file is "process.php".

process.php Code:

<html><body>
<?php
$quantity = $_POST['quantity'];
$item = $_POST['item'];

echo "You ordered ". $quantity . " " . $item . ".<br />";
echo "Thank you for ordering from Tizag Art Supplies!";

?>
</body></html>

As you probably noticed, the name in $_POST['name'] corresponds
to the name that we specified in our HTML form.

Now try uploading the "order.html" and "process.php" files to a PHP enabled server and test them out. If someone selected the item brushes and specified a quantity of 6, then the following
would be displayed on "process.php":

process.php Code:

You ordered 6 brushes.
Thank you for ordering from Tizag Art Supplies!

PHP & HTML Form Review

A lot of things were going on in this example. Let us step through it to be sure you understand what was going on.

  1. We first created an HTML form "order.html" that had two input fields
    specified, "item" and "quantity".
  2. We added two attributes to the form tag to point to "process.php" and
    set the method to "post".
  3. We had "process.php" get the information that was posted
    by setting new variables equal to the values in the $_POST associative array.
  4. We used the PHP echo function to output the customers order.

Remember, this lesson is only to teach you how to use PHP to get information
from HTML forms. The example on this page should not be used for a real business.

PHP Switch Statement

0

Category:

For example we might have a variable that stores travel destinations and you want
to pack according to this destination variable. In this example you might have
20 different locations that you would have to check with a nasty long block
of If/ElseIf/ElseIf/ElseIf/... statements. This doesn't sound like much fun to code,
let's see if we can do something different.

PHP Switch Statement: Speedy Checking

With the use of the switch statement you can check for all these
conditions at once, and the great thing is that it is actually more efficient
programming to do this. A true win-win situation!

The way the Switch statement works is it takes a single variable as input
and then checks it against all the different cases you set up for that
switch statement. Instead of having to check that variable one at a time,
as it goes through a bunch of If Statements, the Switch statement only has to check
one time.



PHP Switch Statement Example


In our example the single variable will be $destination

and the cases will be: Las Vegas, Amsterdam, Egypt, Tokyo, and the Caribbean Islands.

PHP Code:

$destination = "Tokyo";
echo "Traveling to $destination<br />";
switch ($destination){
 case "Las Vegas":
  echo "Bring an extra $500";
  break;
 case "Amsterdam":
  echo "Bring an open mind";
  break; 
 case "Egypt":
  echo "Bring 15 bottles of SPF 50 Sunscreen";
  break; 
 case "Tokyo":
  echo "Bring lots of money";
  break;
 case "Caribbean Islands":
  echo "Bring a swimsuit";
  break; 
}

Display:

Traveling to Tokyo

Bring lots of money
The value of $destination was Tokyo, so when PHP performed the switch

operating on $destination in immediately did a search for a case with the
value of "Tokyo". It found it and proceeded to execute the code that existed
within that segment.

You might have noticed how each case contains a break; at the end of its code area. This
break prevents the other cases from being executed. If the above example did not
have any break statements then all the cases that follow Tokyo would have been executed as well.
Use this knowledge to enhance the power of your switch statements!
The form of the switch statement is rather unique, so spend some time reviewing it
before moving on. Note: Beginning programmers should always include the break; to
avoid any unnecessary confusion.

PHP Switch Statement: Default Case

You may have noticed the lack of a place for code when the
variable doesn't match our condition. The if statement has the else clause and
the switch statement has the default case.

It's usually a good idea to always include the default case in all your switch
statements. Below is a variation of our example that will result in none of the cases
being used causing our switch statement to fall back and use the default case. Note: the word
case does not appear before the word default, as default is a special keyword!


PHP Code:

$destination = "New York";
echo "Traveling to $destination<br />";
switch ($destination){
 case "Las Vegas":
  echo "Bring an extra $500";
  break;
 case "Amsterdam":
  echo "Bring an open mind";
  break;
 case "Egypt":
  echo "Bring 15 bottles of SPF 50 Sunscreen";
  break; 
 case "Tokyo":
  echo "Bring lots of money";
  break; 
 case "Caribbean Islands":
  echo "Bring a swimsuit";
  break;  
 default:
  echo "Bring lots of underwear!";
  break;

}

Display:

Traveling to New York

Bring lots of underwear!

PHP If / else If

0

Category:

PHP - Elseif

An if/else statement is great if you only need to check for one condition. However,
what would you do if you wanted to check if your $employee variable was the company owner
Bob, the Vice President Ms. Tanner, or a regular employee? To check for these different conditions
you would need the elseif statement

PHP - Elseif What is it?

An if statement is made up of the keyword "if" and a conditional statement (i.e. $name == "Ted").
Just like an if statement, an elseif statement also contains a conditional statement, but it must be preceded
by an if statement. You cannot have an elseif statement without first having an if statement.

When PHP evaluates your If...elseif...else statement it will first see if the If statement is true. If that
tests comes out false it will then check the first elseif statement. If that is false it will either check the next
elseif statement, or if there are no more elseif statements, it will evaluate the else segment, if one exists (I don't
think I've ever used the word "if" so much in my entire life!). Let's take a look at a real world example.

PHP - Using Elseif with If...Else

Let's start out with the base case. Imagine we have a simpler version of the problem described above.
We simply want
to find out if the employee is the Vice President Ms. Tanner. We only need an if else statement for
this part of the example.


PHP Code:

$employee = "Bob";
if($employee == "Ms. Tanner"){
 echo "Hello Ma'am";
} else {
 echo "Morning";
}

Now, if we wanted to also check to see if the big boss Bob was the employee we need
to insert an elseif clause.


PHP Code:

$employee = "Bob";
if($employee == "Ms. Tanner"){
 echo "Hello Ma'am";
} elseif($employee == "Bob"){
 echo "Good Morning Sir!";
}else {
 echo "Morning";
}

Display:

Good Morning Sir!

PHP first checked to see if $employee was equal to "Ms. Tanner", which evaluated to
false. Next, PHP checked the first elseif statement. $employee did in
fact equal "Bob" so the phrase "Good Morning Sir!" was printed out. If we wanted
to check for more employee names we could insert more elseif statements!




Remember that an elseif statement cannot be used unless it is preceded
by an if statement!

PHP if statement : how to write logic in PHP ?

0

Category:

The PHP If Statement

The if statement is necessary for most programming, thus it is important in PHP. Imagine that on January
1st you want to print out "Happy New Year!" at the top of your personal web page. With the use of PHP if statements you could have this process automated,
months in advance, occuring every year on January 1st.
This idea of planning for future
events is something you would never have had the opportunity of doing if you
had just stuck with HTML.

If Statement Example

The "Happy New Year" example would be a little difficult for you
to do right now, so let us instead start off with the basics of the if statement.
The PHP if statement tests to see if a value is true, and if it is a segment of
code will be executed. See the example below for the form of a PHP if statement.

PHP Code:

$my_name = "someguy";

if ( $my_name == "someguy" ) {
 echo "Your name is someguy!<br />";
}
echo "Welcome to my homepage!";

Display:

Your name is someguy!

Welcome to my homepage!

Did you get that we were comparing the variable $my_name with "someguy" to see if they
were equal? In PHP you use the double equal sign (==) to compare values.
Additionally, notice that because the if statement turned out to be true, the code segment
was executed, printing out "Your name is someguy!". Let's go a bit more in-depth into this example
to iron out the details.
  • We first set the variable $my_name equal to "someguy".
  • We next used a PHP if statement to check if the value contained in the
    variable $my_name was equal to "someguy"
  • The comparison between $my_name and "someguy" was done with a double equal
    sign "==", not a single equals"="! A single equals is for assigning a value
    to a variable, while a double equals is for checking if things are equal.
  • Translated into english the PHP statement ( $my_name == "someguy" ) is ( $my_name
    is equal to "someguy" ).
  • $my_name is indeed equal to "someguy" so the echo statement is executed.

A False If Statement

Let us now see what happens when a PHP if statement is not true, in
other words, false. Say that we changed the above example to:

PHP Code:

$my_name = "anotherguy";

if ( $my_name == "someguy" ) {
 echo "Your name is someguy!<br />";
}
echo "Welcome to my homepage!";

Display:

Welcome to my homepage!


  • If you work hard then you will succeed.



  • Else, if you do not work hard, then you will fail.


  • How does this translate into something useful for PHP developers?
    Well consider this:

    Someone comes to your website and you want to ask
    this visitor her name if it is her first time coming to your site. With an if statement
    this is easy. Simply have a conditional statement to check, "are
    you visiting for the first time". If the condition is true, then take them to
    the "Insert Your Name" page, else let her view the website as normal because you have already asked her for her name
    in the past.


    If/Else an Example

    Using these conditional statements can add a new layers of "cool" to your
    website. Here's the basic form of an if/else statement in PHP.

    PHP Code:

    $number_three = 3;
    
    if ( $number_three == 3 ) {
     echo "The if statement evaluated to true";
    } else {
     echo "The if statement evaluated to false";
    }
    

    Display:

    The if statement evaluated to true
    This is a lot to digest in one sitting, so let us step through the
    code, line by line.

    • We first made a PHP variable called $number_three and set it equal to 3.
    • In this example we compared a variable to
      an integer value. To do such a comparison we use "==", which in English means "Is Equal To".
    • $number_three is indeed Equal To 3 and so this statement will evaluate to true.
    • All code that is contained between the opening curly brace "{" that follows the if
      statement and the closing curly brace "}" will be executed when the if statement is true.
    • The code contained within the else segment will not used.

    Execute Else Code with False

    On the other hand, if the if statement was false, then the code contained in the else segment would have been
    executed. Note that the code within the if and else cannot both be executed, as
    the if statement cannot evaluate to both true and false at one time! Here is what would happen
    if we changed to $number_three to anything besides the number 3.


    PHP Code:

    $number_three = 421;
    
    if ( $number_three == 3 ) {
     echo "The if statement evaluated to true";
    } else {
     echo "The if statement evaluated to false";
    }
    
    

    Display:

    The if statement evaluated to false
    The variable was set to 421, which is not equal to 3 and the if statement was false. As you can see,
    the code segment contained within the else was used in this case.

    PHP Include , how to use include in PHP ?

    0

    Category:

    PHP Include

    Without understanding much about the details of PHP, you can save yourself a great deal of time with the use of the PHP include command. include takes a file name and simply inserts that file's contents into the script that issued the include command.

    An Include Example

    Say we wanted to create a common menu file that all our pages
    will use. A common practice for naming files that are to be included is to use the ".php" extension. Since we want to create a common menu
    let's save it as "menu.php".

    menu.php Code:

    <html>
    <body>
    <a href="http://www.example.com/index.php">Home</a> - 
    <a href="http://www.example.com/about.php">About Us</a> - 
    <a href="http://www.example.com/links.php">Links</a> - 
    
    <a href="http://www.example.com/contact.php">Contact Us</a> <br />
    

    Save the above file as "menu.php". Now create a new file, "index.php" in the same directory as
    "menu.php". Here we will take advantage of the include command to add our common menu.

    index.php Code:

    <?php include("menu.php"); ?>
    
    <p>This is my home page that uses a common menu to save me time when I add
    new pages to my website!</p>
    </body>
    </html>
    

    Display:

    Home -
    About Us -

    Links -
    Contact Us
    This is my home page that uses a common menu to save me time when I add new pages to my website!
    And we would do the same thing for "about.php", "links.php", and "contact.php". Just think
    how terrible it would be if you had 15 or more pages with a common menu and you decided to add
    another web page to that site. You would have to go in and manually edit every single file to add this
    new page, but with include files you simply have to change "menu.php" and all your problems are solved.
    Avoid such troublesome occasions with a simple include file.

    What do Visitors See?

    If we were to use the include command to insert a menu on each of our web pages, what
    would the visitor see if they viewed the source of "index.php"? Well, because the include command
    is pretty much the same as copying and pasting, the visitors would see:

    View Source of index.php to a Visitor:

    <html>
    
    <body>
    <a href="index.php">Home</a> - 
    <a href="about.php">About Us</a> - 
    <a href="links.php">Links</a> - 
    
    <a href="contact.php">Contact Us</a> <br />
    <p>This is my home page that uses a common menu to save me time when I add
    new pages to my website!</p>
    </body>
    </html>
    

    The visitor would actually see all the HTML code as one long line of HTML code, because
    we have not inserted any new line characters. We did some formatting above to make it easier to read. We will be discussing new line characters later.

    Include Recap

    The include command simply takes all the text that exists in the specified file and copies
    it into the file that uses the include command. Include is quite useful when you want to include the same PHP, HTML, or text segment on multiple pages of a website. The include command is used widely by PHP web developers. Like PHP Echo, include is not a function, but a language construct.

    Require vs Include

    When you include a file with the include command and PHP cannot
    find it you will see an error message like the following:

    PHP Code:

    <?php
    include("noFileExistsHere.php");
    echo "Hello World!";
    ?>
    
    

    Display:

    Warning: main(noFileExistsHere.php): failed to open stream: No such file or directory in /home/websiteName/FolderName/tizagScript.php on line 2
    Warning: main(): Failed opening 'noFileExistsHere.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/websiteName/FolderName/tizagScript.php on line 2



    Hello World!

    Notice that our echo statement is still executed, this is because a Warning does not prevent our PHP script from running.
    On the other hand, if we did the same example but used the require statement we would get something like the following example.

    PHP Code:

    <?php
    require("noFileExistsHere.php");
    echo "Hello World!";
    ?>
    

    Display:

    Warning: main(noFileExistsHere.php): failed to open stream: No such file or directory in /home/websiteName/FolderName/tizagScript.php on line 2


    Fatal error: main(): Failed opening required 'noFileExistsHere.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/websiteName/FolderName/tizagScript.php on line 2

    The echo statement was not executed because our script execution died after the require command returned a fatal error! We recommend that you use require instead of include because your scripts should not be executing if necessary files are missing or misnamed.

    PHP Operators

    0

    Category:

    PHP - Operators

    There are many operators used in PHP, so we have separated them into
    the following categories to make it easier to learn them all.
    • Assignment Operators
    • Arithmetic Operators
    • Comparison Operators
    • String Operators
    • Combination Arithmetic & Assignment Operators


    Assignment Operators

    Assignment operators are used to set a variable equal to a value or set
    a variable to another variable's value. Such an assignment of value is done with
    the "=", or equal character. Example:


    • $my_var = 4;
    • $another_var = $my_var;
    Now both $my_var and $another_var contain the value 4. Assignments can also be used in conjunction with arithmetic operators.

    Arithmetic Operators

    OperatorEnglishExample
    + Addition 2 + 4
    - Subtraction 6 - 2
    * Multiplication 5 * 3
    / Division 15 / 3
    % Modulus 43 % 10


    PHP Code:

    $addition = 2 + 4; 
    $subtraction = 6 - 2; 
    $multiplication = 5 * 3; 
    $division = 15 / 3; 
    $modulus = 5 % 2; 
    echo "Perform addition: 2 + 4 = ".$addition."<br />"; 
    echo "Perform subtraction: 6 - 2 = ".$subtraction."<br />"; 
    echo "Perform multiplication:  5 * 3 = ".$multiplication."<br />"; 
    echo "Perform division: 15 / 3 = ".$division."<br />"; 
    echo "Perform modulus: 5 % 2 = " . $modulus 
     . ". Modulus is the remainder after the division operation has been performed.  
     In this case it was 5 / 2, which has a remainder of 1.";
    

    Display:

    Perform addition: 2 + 4 = 6

    Perform subtraction: 6 - 2 = 4


    Perform multiplication: 5 * 3 = 15

    Perform division: 15 / 3 = 5

    Perform modulus: 5 % 2 = 1. Modulus is the remainder after the division operation has been performed.
    In this case it was 5 / 2, which has a remainder of 1.

    Comparison Operators

    Comparisons are used to check the relationship between variables and/or
    values. If you would like to see a simple example of a comparison operator in action, check out our
    If Statement Lesson. Comparison
    operators are used inside conditional statements and evaluate to either true
    or false. Here are the most important comparison operators of PHP.



    Assume: $x = 4 and $y = 5;

    OperatorEnglish Example Result
    == Equal To $x == $y false
    != Not Equal To $x != $y true
    < Less Than $x < $y true
    > Greater Than $x > $y false
    <= Less Than or Equal To $x <= $y true
    >= Greater Than or Equal To $x >= $y false



    String Operators

    As we have already seen in the Echo
    Lesson
    , the period "." is used to add two strings together, or more technically,
    the period is the concatenation operator for strings.



    PHP Code:

    $a_string = "Hello";
    $another_string = " Billy";
    $new_string = $a_string . $another_string;
    echo $new_string . "!";
    

    Display:

    Hello Billy!


    Combination Arithmetic & Assignment Operators

    In programming it is a very common task to have to increment a variable by some fixed amount. The
    most common example of this is a counter. Say you want to increment a counter by 1, you would
    have:

    • $counter = $counter + 1;
    However, there is a shorthand for doing this.
    • $counter += 1;
    This combination assignment/arithmetic operator would accomplish the same task. The downside to this
    combination operator is that it reduces code readability to those programmers who are not used to such
    an operator. Here are some examples of other common
    shorthand operators. In general, "+=" and "-=" are the most widely used combination operators.

    OperatorEnglish Example Equivalent Operation
    +=Plus Equals $x += 2; $x = $x + 2;
    -=Minus Equals $x -= 4; $x = $x - 4;
    *=Multiply Equals $x *= 3; $x = $x * 3;
    /=Divide Equals $x /= 2; $x = $x / 2;
    %=Modulo Equals $x %= 5; $x = $x % 5;
    .=Concatenate Equals $my_str.="hello"; $my_str = $my_str . "hello";

    Pre/Post-Increment & Pre/Post-Decrement

    This may seem a bit absurd, but there is even a shorter shorthand for the common
    task of adding 1 or subtracting 1 from a variable. To add one to a variable or "increment"
    use the "++" operator:
    • $x++; Which is equivalent to $x += 1; or $x = $x + 1;
    To subtract 1 from a variable, or "decrement" use the "--" operator:

    • $x--; Which is equivalent to $x -= 1; or $x = $x - 1;
    In addition to this "shorterhand" technique, you can specify whether you
    want to increment before the line of code is being executed or after the
    line has executed. Our PHP code below will display the difference.


    PHP Code:

    $x = 4;
    echo "The value of x with post-plusplus = " . $x++;
    echo "<br /> The value of x after the post-plusplus is " . $x;
    $x = 4;
    echo "<br />The value of x with with pre-plusplus = " . ++$x;
    echo "<br /> The value of x after the pre-plusplus is " . $x;
    

    Display:

    The value of x with post-plusplus = 4

    The value of x after the post-plusplus is = 5


    The value of x with with pre-plusplus = 5

    The value of x after the pre-plusplus is = 5
    As you can see the value of $x++ is not reflected in the echoed text because
    the variable is not incremented until after the line of code is executed. However,
    with the pre-increment "++$x" the variable does reflect the addition immediately.

    PHP String Creation , How to create String in PHP ?

    0

    Category:

    PHP - String Creation

    Before you can use a string you have to create it! A string can be used directly
    in a function or it can be stored in a variable. Below we create the exact same string twice: first
    storing it into a variable and in the second case we send the string directly to echo.


    PHP Code:

    $my_string = "Tizag - Unlock your potential!";
    echo "Tizag - Unlock your potential!";
    echo $my_string;
    

    In the above example the first string will be stored into the variable $my_string,
    while the second string will be used in the echo and not be stored. Remember to
    save your strings into variables if you plan on using them more than once! Below is the output from
    our example code. They look identical just as we thought.


    Display:

    Tizag - Unlock your potential!
    Tizag - Unlock your potential!



    PHP - String Creation Single Quotes


    Thus far we have created strings using double-quotes, but it is just as correct
    to create a string using single-quotes, otherwise known as apostrophes.


    PHP Code:

    $my_string = 'Tizag - Unlock your potential!';
    echo 'Tizag - Unlock your potential!';
    echo $my_string;
    

    If you want to use a single-quote within the string you have to escape the single-quote
    with a backslash \ . Like this: \' !



    PHP Code:

    echo 'Tizag - It\'s Neat!';
    

    PHP - String Creation Double-Quotes

    We have used double-quotes and will continue to use them as the
    primary method for forming strings. Double-quotes allow for many special escaped characters
    to be used that you cannot do with a single-quote string. Once again, a backslash is used to escape a character.



    PHP Code:

    $newline = "A newline is \n";
    $return = "A carriage return is \r";
    $tab = "A tab is \t";
    $dollar = "A dollar sign is \$";
    $doublequote = "A double-quote is \"";
    

    Note: If you try to escape a character that doesn't need to be, such as an apostrophe, then
    the backslash will show up when you output the string.

    These escaped characters are not very useful for outputting to a web page because HTML ignore extra white space.
    A tab, newline, and carriage return are all examples of extra (ignorable) white space. However, when writing to a file that
    may be read by human eyes these escaped characters are a valuable tool!


    PHP - String Creation Heredoc

    The two methods above are the traditional way to create strings in most
    programming languages. PHP introduces a more robust string creation tool called
    heredoc that lets the programmer create multi-line strings without using
    quotations. However, creating a string using heredoc is more difficult and can lead to
    problems if you do not properly code your string! Here's how to do it:



    PHP Code:

    $my_string = <<<TEST
    Tizag.com
    Webmaster Tutorials
    Unlock your potential!
    TEST;
    
    echo $my_string;
    

    There are a few very important things to remember when using heredoc.

    • Use <<< and some identifier that you choose to begin the heredoc. In this example we chose TEST as our
      identifier.
    • Repeat the identifier followed by a semicolon to end the heredoc string creation. In this example that was
      TEST;
    • The closing sequence TEST; must occur on a line by itself and cannot be indented!

    Another thing to note is that when you output this multi-line string to a web page, it will not span multiple lines
    because we did not have any <br /> tags contained inside our string! Here is the output made from the code above.

    PHP Syntax : who to write php code

    0

    Category:

    PHP's syntax and semantics are similar to most other programming languages (C, Java, Perl)
    with the addition that all PHP code is contained with a tag, of sorts. All
    PHP code must be contained within the following...

    PHP Code:

    <?php
    ?>
    
    or the shorthand PHP tag that requires shorthand support to be enabled
    on your server...
    
    <?
    ?>
    

    If you are writing PHP scripts and plan on distributing them, we suggest
    that you use the standard form (which includes the ?php) rather than the shorthand
    form. This will ensure that your scripts will work, even when running on other
    servers with different settings.

    How to Save Your PHP Pages

    If you have PHP inserted into your HTML and want the
    web browser to interpret it correctly, then you must save the file with a .php extension,
    instead of the standard .html extension. So be sure to check that you are saving your files
    correctly. Instead of index.html, it should be index.php if there
    is PHP code in the file.




    Example Simple HTML & PHP Page

    Below is an example of one of the easiest PHP and HTML page that you
    can create and still follow web standards.

    PHP and HTML Code:

    <html>
    <head>
    <title>My First PHP Page</title>
    
    </head>
    <body>
    <?php
    echo "Hello World!";
    ?>
    </body>
    </html>
    

    Display:

    Hello World!

    If you save this file (e.g. helloworld.php) and place it on PHP enabled server and load it up in your web browser, then you should see
    "Hello World!" displayed. If not, please check that you followed our example
    correctly.
    We used the PHP command echo to write "Hello World!" and we will be talking in greater depth about how echo is special later on in this tutorial.

    The Semicolon!

    As you may or may not have noticed in the above example, there was a semicolon after
    the line of PHP code. The semicolon signifies the end of a PHP statement and
    should never be forgotten. For example, if we repeated our "Hello World!" code several times, then we would
    need to place a semicolon at the end of each statement.

    PHP and HTML Code:

    <html>
    <head>
    <title>My First PHP Page</title>
    
    </head>
    <body>
    <?php
    echo "Hello World! ";
    echo "Hello World! ";
    echo "Hello World! ";
    echo "Hello World! ";
    echo "Hello World! ";
    ?>
    </body>
    </html>
    

    Display:

    Hello World!
    Hello World!
    Hello World!
    Hello World!
    Hello World!

    White Space

    As with HTML, whitespace is ignored between PHP statements. This means it is OK to have
    one line of PHP code, then 20 lines of blank space before the next line of PHP code. You can also
    press tab to indent your code and the PHP interpreter will ignore those spaces as well.


    PHP and HTML Code:

    <html>
    <head>
    <title>My First PHP Page</title>
    </head>
    <body>
    
    <?php
    echo "Hello World!";        
    
    
    
     echo "Hello World!";
    
    
    ?>
    </body>
    </html>
    

    Display:

    Hello World!Hello World!

    PHP Variables :

    virtualinfocom way

    A variable is a means of storing a value, such as text string "Hello World!"
    or the integer value 4. A variable can then be reused throughout
    your code, instead of having to type out the actual value over and over again. In PHP you define a variable with the following form:
    • $variable_name = Value;

    If you forget that dollar sign at the beginning, it will not work. This is a common
    mistake for new PHP programmers!

    Note: Also, variable names are case-sensitive, so use the exact same capitalization when using a variable. The variables $a_number and $A_number are different variables in PHP's eyes.

    A Quick Variable Example

    Say that we wanted to store the values that we talked about in the above paragraph.
    How would we go about doing this? We would first want to make a variable name and then
    set that equal to the value we want. See our example below for the correct way to do this.

    PHP Code:

    <?php
    $hello = "Hello World!";
    $a_number = 4;
    $anotherNumber = 8;
    ?>
    
    
    Note for programmers: PHP does not require variables to be declared before
    being initialized.

    PHP Variable Naming Conventions

    There are a few rules that you need to follow when choosing a name for your
    PHP variables.
    • PHP variables must start with a letter or underscore "_".
    • PHP variables may only be comprised of alpha-numeric characters and underscores. a-z, A-Z, 0-9, or _ .
    • Variables with more than one word should be separated with underscores. $my_variable
    • Variables with more than one word can also be distinguished with capitalization. $myVariable

    Outputting a String

    To output a string, like we have done in previous lessons, use PHP echo. You can place either a string variable or you can use quotes, like we do below, to create a string that the echo function will output.

    PHP Code:

    <?php
    $myString = "Hello!";
    echo $myString;
    echo "<h5>I love using PHP!</h5>";
    ?>
    
    

    Display:

    Hello!
    I love using PHP!
    In the above example we output "Hello!" without a hitch. The text we are
    outputting is being sent to the user in the form of a web page, so it is important that we use proper
    HTML syntax!
    In our second echo statement we use echo to write a valid Header 5 HTML statement.
    To do this we simply put the <h5> at the beginning of the string and closed it at the end of the
    string. Just because you're using PHP to make web pages does not mean you can forget
    about HTML syntax!



    Careful When Echoing Quotes!

    It is pretty cool that you can output HTML with PHP. However, you must be careful when using HTML code or any other string that includes quotes! Echo uses quotes to define the beginning and end of the string, so you must use one of the following tactics if your string contains quotations:
    • Don't use quotes inside your string
    • Escape your quotes that are within the string with a backslash. To escape a quote
      just place a backslash directly before the quotation mark, i.e. \"
    • Use single quotes (apostrophes) for quotes inside your string.

    See our example below for the right and wrong use of echo:


    PHP Code:

    <?php
    // This won't work because of the quotes around specialH5!
    echo "<h5 class="specialH5">I love using PHP!</h5>";  
    
    // OK because we escaped the quotes!
    echo "<h5 class=\"specialH5\">I love using PHP!</h5>";  
    
    // OK because we used an apostrophe '
    echo "<h5 class='specialH5'>I love using PHP!</h5>";  
    ?>
    
    

    If you want to output a string that includes quotations, either use an apostrophe ( ' ) or escape the
    quotations by placing a backslash in front of it ( \" ). The backslash will tell PHP that you want the quotation
    to be used within the string and NOT to be used to end echo's string.

    Echoing Variables

    Echoing variables is very easy. The PHP developers put in some extra work
    to make the common task of echoing all variables nearly foolproof! No quotations are
    required, even if the variable does not hold a string. Below is the correct
    format for echoing a variable.




    PHP Code:

    <?php
    $my_string = "Hello Bob.  My name is: ";
    $my_number = 4;
    $my_letter = a;
    echo $my_string;
    echo $my_number;
    echo $my_letter;
    ?>
    


    Display:

    Hello Bob. My name is: 4a

    Echoing Variables and Text Strings

    You can also place variables inside of double-quoted strings (e.g. "string here and a $variable"). By putting a variable inside the quotes (" ") you are telling PHP that you want it to grab the string value of that variable and use it in the string. The example below shows an example of this cool feature.




    PHP Code:

    <?php
    $my_string = "Hello Bob.  My name is: ";
    echo "$my_string Bobettta <br />";
    echo "Hi, I'm Bob.  Who are you? $my_string <br />";
    echo "Hi, I'm Bob.  Who are you? $my_string Bobetta";
    ?>
    

    Display:

    Hello Bob. My name is: Bobetta

    Hi, I'm Bob. Who are you? Hello Bob. My name is:


    Hi, I'm Bob. Who are you? Hello Bob. My name is: Bobetta

    By placing variables inside a string you can save yourself some time and make your code easier to read, though it does take some getting used to. Remember to use double-quotes, single-quotes will not grab the value of the string. Single-quotes will just output the variable name to the string, like )$my_string), rather than (Hello Bob. My name is: ).

    Installing MySQL on Windows

    0

    Category:

    To run MySQL on Windows, you need the following:


    • A Windows operating system such as Windows 2000, Windows XP,
      Windows Vista, Windows Server 2003, or Windows Server 2008. Both
      32-bit and 64-bit versions are supported.

      In addition to running MySQL as a standard application, you can
      also run the MySQL server as a Windows service. By using a
      service you can monitor and control the operation of the server
      through the standard Windows service management tools.


      Generally, you should install MySQL on Windows using an account
      that has administrator rights. Otherwise, you may encounter
      problems with certain operations such as editing the
      PATH environment variable or accessing the
      Service Control Manager. Once installed,
      MySQL does not need to be executed using a user with
      Administrator privileges.


    • TCP/IP protocol support.


    • Enough space on the hard drive to unpack, install, and create
      the databases in accordance with your requirements (generally a
      minimum of 200 megabytes is recommended.)



    In addition to the MySQL Server package, you may need or want
    additional components to use MySQL with your application or
    development environment. These include, but are not limited to:


    • If you plan to connect to the MySQL server via ODBC, you need a
      Connector/ODBC driver.


    • If you plan to use MySQL server with .NET applications, you need
      the Connector/NET driver.

    MySQL distributions for Windows can be downloaded from
    http://dev.mysql.com/downloads/. See Section 2.1.3, “How to Get MySQL”.


    MySQL for Windows is available in several distribution formats,
    detailed below. Generally speaking, you should use a binary
    distribution that includes an installer. It is simpler to use than
    the others, and you need no additional tools to get MySQL up and
    running. The installer for the Windows version of MySQL, combined
    with a GUI Config Wizard, automatically installs MySQL, creates an
    option file, starts the server, and secures the default user
    accounts.



    • Binary installer distribution. The installable distribution
      comes packaged as a Microsoft Windows Installer (MSI) package
      that you can install manually or automatically on your systems.
      Two formats are available, an essentials package that contains
      all the files you need to install and configure MySQL, but no
      additional components, and a complete package that includes
      MySQL, configuration tools, benchmarks and other components. For
      more information on the specific differences, see
      Section 2.5.2, “Choosing An Installation Package”

      For instructions on installing MySQL using one of the MSI
      installation packages, see
      Section 2.5.3, “Installing MySQL with the MSI Package”.




    • Standard binary distribution format packaged as a Zip file
      containing all of the necessary files that you unpack into your
      chosen location. This package contains all of the files in the
      full Windows MSI Installer package, but does not including an
      installation program.

      For instructions on installing MySQL using the Zip file, see
      Section 2.5.5, “Installing MySQL from a noinstall Zip Archive”.



    • The source distribution contains all the code and support files
      for building the executables using the Visual Studio compiler
      system.

      For instructions on building MySQL from source on Windows, see
      Section 2.5.10, “Installing MySQL from Source on Windows”.

    MySQL on Windows considerations:




    • Large Table Support

      If you need tables with a size larger than 4GB, install MySQL on
      an NTFS or newer file system. Do not forget to use
      MAX_ROWS and
      AVG_ROW_LENGTH when you create tables. See Section 12.1.17, “CREATE TABLE Syntax”.




    • MySQL and Virus Checking
      Software


      Using virus scanning software such as Norton/Symantec Anti-Virus
      on directories containing MySQL data and temporary tables can
      cause issues, both in terms of the performance of MySQL and the
      virus-scanning software mis-identifying the contents of the
      files as containing spam. This is because of the fingerprinting
      mechanism used by the virus scanning software, and the way in
      which MySQL rapidly updates different files, which may be
      identified as a potential security risk.

      After installing MySQL Server, it is recommended that you
      disable virus scanning on the main directory
      (datadir) being used to store your MySQL table data. There is usually a system built into the
      virus scanning software to allow certain directories to be
      specifically ignored during virus scanning.



      In addition, by default, MySQL creates temporary files in the
      standard Windows temporary directory. To prevent the temporary
      files also being scanned, you should configure a separate
      temporary directory for MySQL temporary files and add this to
      the virus scanning exclusion list. To do this, add a configuration option for the
      tmpdir parameter to your my.ini configuration file.

    Installing MySQL

    0

    Category:

    As we mentioned before, MySQL is not a requirement to use PHP, however they often go hand in hand.

    virtualinfocom will help you how to install MySQL


    Oracle provides a set of binary distributions of MySQL. In addition
    to binaries provided in platform-specific package formats, we offer
    binary distributions for a number of platforms in the form of
    compressed tar files
    (.tar.gz files). For Windows distributions, see
    Section 2.5, “Installing MySQL on Windows”.

    If you want to compile a debug version of MySQL from a source
    distribution, you should add
    --with-debug or
    --with-debug=full to the
    configure command used to configure the
    distribution and remove any -fomit-frame-pointer
    options.


    MySQL tar file binary distributions have names of
    the form
    mysql-VERSION-OS.tar.gz,
    where VERSION is a
    number (for example, 5.1.49), and
    OS indicates the type of operating system
    for which the distribution is intended (for example,
    pc-linux-i686).


    In addition to these generic packages, we also offer binaries in
    platform-specific package formats for selected platforms. See the
    platform specific sections for more information, for more
    information on how to install these.

    You need the following tools to install a MySQL
    tar file binary distribution:


    • GNU gunzip to uncompress the distribution.



    • A reasonable tar to unpack the distribution.
      GNU tar is known to work. Some operating
      systems come with a preinstalled version of
      tar that is known to have problems. For
      example, the tar provided with early versions
      of Mac OS X, SunOS 4.x, Solaris 8, Solaris 9, Solaris 10 and
      OpenSolaris, and HP-UX are known to have problems with long file
      names.




      • On Mac OS X, you can use the preinstalled
        gnutar program.


      • On Solaris 10 and OpenSolaris you can use the preinstalled
        gtar.


      • On other systems with a deficient tar,
        you should install GNU tar first.

    Warning

    If you have previously installed a MySQL installation using your
    operating system native package management system, such as
    yum or apt-get, you may
    experience problems installing using a native binary. Make sure
    your previous MySQL previous installation has been removed
    entirely (using your package management system), and that any
    additional files, such as old versions of your data files, have
    also been removed. You should also check the existence of
    configuration files such as /etc/my.cnf or
    the /etc/mysql directory have been deleted.





    The basic commands that you must execute to install and use a MySQL
    binary distribution are:

    Note

    The following process assumes that you have root (administrator)
    access to your system. Alternatively you can prefix each command
    using the sudo (Linux) or
    pfexec (OpenSolaris) command.


    shell> groupadd mysql
    shell> useradd -g mysql mysql
    shell> cd /usr/local
    shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
    
    shell> ln -s full-path-to-mysql-VERSION-OS mysql
    shell> cd mysql
    shell> chown -R mysql .
    shell> chgrp -R mysql .
    
    shell> scripts/mysql_install_db --user=mysql
    shell> chown -R root .
    shell> chown -R mysql data
    shell> bin/mysqld_safe --user=mysql &
    


    A more detailed version of the preceding description for installing
    a binary distribution follows:

    Note


    The following process assumes that you have root (administrator)
    access to your system. Alternatively you can prefix each command
    using the sudo (Linux) or
    pfexec (OpenSolaris) command.

    1. If your system does not already have a user and group for
      mysqld to run as, you may need to create one.



      shell> groupadd mysql
      shell> useradd -g mysql mysql
      

      Note

      The above will create a user that has login permissions to
      your server. You may wish to disable the account, as the user
      is only required for ownership, not login, purposes.


      These commands add the mysql group and the
      mysql user. The syntax for
      useradd and groupadd may
      differ slightly on different versions of Unix, or they may have
      different names such as adduser and
      addgroup.



      You might want to call the user and group something else instead
      of mysql. If so, substitute the appropriate
      name in the following steps.


    2. Pick the directory under which you want to unpack the
      distribution and change location into it. In the following
      example, we unpack the distribution under
      /usr/local. (The instructions, therefore,
      assume that you have permission to create files and directories
      in /usr/local. If that directory is
      protected, you must perform the installation as
      root.)



      shell> cd /usr/local
      

    3. Obtain a distribution file using the instructions in
      Section 2.1.3, “How to Get MySQL”. For a given release, binary
      distributions for all platforms are built from the same MySQL
      source distribution.


    4. Unpack the distribution, which creates the installation
      directory. Then create a symbolic link to that directory:



      shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
      shell> ln -s full-path-to-mysql-VERSION-OS mysql
      
      The tar command creates a directory named
      mysql-VERSION-OS.
      The ln command makes a symbolic link to that
      directory. This lets you refer more easily to the installation
      directory as /usr/local/mysql.



      With GNU tar, no separate invocation of
      gunzip is necessary. You can replace the
      first line with the following alternative command to uncompress
      and extract the distribution:

      shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
      

    5. Change location into the installation directory:

      shell> cd mysql
      
      You will find several files and subdirectories in the
      mysql directory. The most important for
      installation purposes are the bin and
      scripts subdirectories:





      • The bin directory contains client
        programs and the server. You should add the full path name
        of this directory to your PATH
        environment variable so that your shell finds the MySQL
        programs properly. See
        Section 2.14, “Environment Variables”.



      • The scripts directory contains the
        mysql_install_db script used to
        initialize the mysql database containing
        the grant tables that store the server access permissions.


    6. Ensure that the distribution contents are accessible to
      mysql. If you unpacked the distribution as
      mysql, no further action is required. If you
      unpacked the distribution as root, its
      contents will be owned by root. Change its
      ownership to mysql by executing the following
      commands as root in the installation
      directory:



      shell> chown -R mysql .
      shell> chgrp -R mysql .
      
      The first command changes the owner attribute of the files to
      the mysql user. The second changes the group
      attribute to the mysql group.



    7. If you have not installed MySQL before, you must create the
      MySQL data directory and initialize the grant tables:

      shell> scripts/mysql_install_db --user=mysql
      
      If you run the command as root, include the
      --user option as shown.
      If you run the while logged in as that user, you can omit the
      --user option.



      The command should create the data directory and its contents
      with mysql as the owner.

      After creating or updating the grant tables, you need to restart
      the server manually.


    8. Most of the MySQL installation can be owned by
      root if you like. The exception is that the
      data directory must be owned by mysql. To
      accomplish this, run the following commands as
      root in the installation directory:



      shell> chown -R root .
      shell> chown -R mysql data
      

    9. If the plugin directory is writable by the server, it may be
      possible for a user to write executable code to a file in the
      directory using SELECT
      ... INTO DUMPFILE
      . This can be prevented by making
      plugin_dir read only to the
      server or by setting
      --secure-file-priv to a directory
      where SELECT writes can be made
      safely.


    10. If you want MySQL to start automatically when you boot your
      machine, you can copy
      support-files/mysql.server to the location
      where your system has its startup files. More information can be
      found in the support-files/mysql.server
      script itself and in Section 2.13.1.2, “Starting and Stopping MySQL Automatically”.


    11. You can set up new accounts using the
      bin/mysql_setpermission script if you install
      the DBI and DBD::mysql

      Perl modules. See Section 4.6.14, “mysql_setpermission — Interactively Set Permissions in Grant
      Tables”
      . For
      Perl module installation instructions, see Section 2.15, “Perl Installation Notes”.


    12. If you would like to use mysqlaccess and have
      the MySQL distribution in some nonstandard location, you must
      change the location where mysqlaccess expects
      to find the mysql client. Edit the
      bin/mysqlaccess script at approximately
      line 18. Search for a line that looks like this:



      $MYSQL     = '/usr/local/bin/mysql';    # path to mysql executable
      
      Change the path to reflect the location where
      mysql actually is stored on your system. If
      you do not do this, a Broken pipe error will
      occur when you run mysqlaccess.


    After everything has been unpacked and installed, you should test
    your distribution. To start the MySQL server, use the following
    command:

    shell> bin/mysqld_safe --user=mysql &
    
    If you run the command as root, you must use the
    --user option as shown. The
    value of the option is the name of the login account that you
    created in the first step to use for running the server. If you run
    the command while logged in as mysql, you can
    omit the --user option.


    If the command fails immediately and prints mysqld
    ended
    , you can find some information in the
    host_name.err file
    in the data directory.






    User Comments



    After setting the group to 'mysql', check that the group has write privileges to the directories.
    Otherwise do a 'chmod g+w data'
    Posted by Scott Park on November 29 2004 8:18am[Delete] [Edit]
    In my experience with FreeBSD the groupadd and addgroup commands are not available. Instead you must use the ps utility to add users and groups. Below is the method I used:

    pw groupadd mysql
    pw useradd mysql
    pw groupmod mysql -M mysql
    pw groupshow mysql

    More info can be found on the FreeBSD website:
    http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/users-groups.html


    To Install MYSQL SERVER on FreeBSD (using port collection) you will have to do the following

    cd /usr/ports/databases/mysqlxx-server (xx is server verison)

    make install clean (this installs and clean up after you)

    cp /usr/local/share/mysql/abc.cnf /etc/my.cnf (abc is your choice of configuration file. options include my-huge, my-large, my-medium, my-small)

    cp /usr/local/share/mysql/mysql.server /etc/rc.d/mysql.server

    now you may install the db using :

    mysql_intsall_db --user=mysql

    verify that the mysql db in /var/db/mysql have the right user and group ownership (owner/group should be mysql)

    If note just change the owner/group setting for the folder and sub-folders and files /var/db/mysql

    You can now start the deamon
    mysql_safe &

    don't forget to change mysql admin password and imo also restrict admin user access only to local machine.

    NOTE : You can change the location of the db file by including the directory switch in your mysql_install_db command (--basedir=path). You can also choose a different user to run your mysql daemon.

    For fresh FreeBSD command you will notice that you need to use the full path to the executables : /usr/local/bin/mysqld_safe


    Wole Akpose's post was indispensable for a newbie like me installing mysql5 on FreeBSD. I installed on FreeBSD 6.0. Here are a few additional items to note on his post:

    1) A minor typo... "mysql_install_db" not "mysql_intsall_db"

    2) Per his instructions, I did have to chgrp my /var/db/mysql files (chgrp -R mysql /var/db/mysql)

    3) I'm assuming there's something wrong with my setup, since plain old "mysql_safe &" doesn't work for me. Instead I have to use this "cd /var/db/mysql ; /usr/local/bin/mysqld_safe &"

    4) For reasons unknown to me, mysql doesn't start automatically on reboot. So I placed an sh file in /etc/rc.d that simply contains the mysql_safe call. (FYI, I do have mysql.server file in place)


    Sorry about the typos. Thanks for the corrections.

    mysqld_safe is the correct command.

    Note that you can also either create a script that simply repeat these processes or update your make file to take these actions automatically.

    If you have to install for multiple machines, a script is the way to go


    While running FC3, I was not able to start the Mysql service until I manually created /var/run/mysqld/ for the PID file.

    mkdir /var/run/mysqld
    chown -R /var/run/mysqld mysqld
    chgrp -R /var/run/mysqld mysqld


    mysql binary installation:---

    In Fedora core 8 to start mysql service manually we need to create mysqld folder in /var/run and set permission as shown below

    # groupadd mysqld
    # useradd –g mysqld mysqld
    # mkdir /var/run/msqld
    # chown –R /var/run/mysqld mysqld
    # chmod 770 /var/run/mysqld


    I'm using Ubuntu 7.10 with the MySQL 5.1.22 .tar.gz binary distribution. I needed to add --no-defaults to the ./scripts/mysql_install_db for it to work properly.


    I am on linux-mint 4.0, which is basically Ubuntu 7. I would like to reiterate that without the --no-defaults option the mysql_install_db will not run correctly.


    Note that if you install to a location different than /usr/local (or other standard location) then you must ensure that the libraries form <base_dir>/lib/mysql are found by the dynamic linker.

    On my linux I achieved that by appending <base_dir>/lib/mysql to the LD_LIBRARY_PATH environment variable. I also had to export the variable with

    $ export LD_LIBRARY_PATH

    An alternative is to add the mysql library dir to the set of standard library paths using ldconfig.


    For PowerPC Mac OS X 10.5 the only download available is in .tar.gz format. The instructions here for this kind on install do not apply to Mac OS X because the groupadd command does not exists on Leopard.

    Can anyone post an updated install procedure?


    For my installation of version 5.1.32, step 7 requires an additional piece of information. When I ran the installation script to create the db tables, I had to specify my data directory using the --datadir= option. If I didn't, the daemon would fail with the following error:

    <i>090327 15:04:12 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.</i>

    After I did, I was able to start the daemon and run the upgrade script to create the plugin and host tables.




    I am on linux-mint 4.0, which is basically Ubuntu 7. I would like to reiterate that without the --no-defaults option the mysql_install_db will not run correctly.

    It really works thank you)


    Here there are two commands missing which are:

    shell> cp /usr/local/mysql/support-files/my-small.cnf /etc/my.cnf

    #comment this would copy the desired config you want to /etc as my.cnf


    shell> cp /usr/local/mysql/support-files/mysql.server /etc/init.d/

    #comment this would copy the daemon for mysqld to init.d to be initialize it.

    to start the mysqld

    shell>/etc/init.d/mysql.server start


    I installed generic binaries (5.1.42) for ,Mandriva 2010.01 based on these instructions.

    Few tips: If you use 'useradd mysql' like in this example - you get an account with which you can log in to KDE and has a '/usr/home/mysql' directory. You would also see it in the login splash. You need to do 'useradd -r mysql' so no home directory and account are created. The same for groupadd. Use the '-r' flag so the group gets a group id lower than 500 to be considered a system group.

    No matter what I did I could not run the scripts in the $MYSQL_HOME/scripts or $MYSQL_HOME/bin with any other user than root. No 'chmode' command seemed to help. You have to perform the installation with the root account (e.g. su) plus to use the '--user=root' flag in every installation script.

    I used the '/usr/local' dir to place the installation but I have a data partition under '/data' where I wanted all my large files to reside. I used the '--datadir=/data' flag to tell mysql where the db files will reside.

    I could not set mysql to start automatically using the instructions here. I did the '/etc/init.d' linking, like it says here - but when I tried to run '/etc/init.d/mysql.server start' I got a permission error.

    This was a show-stopper for me so I tried a different approach. I used 'urpmi mysql' to install the mysql package. This got me up and running plus auto-starting mysql in under 2 minutes.

    Then, I checked how the installer configured the '/etc/init.d' linking and found out the links are totally different than what it says here. The installer also places the main mysql installation under '/var/lib'.

    Then, in the '/etc/my.cfg' file - I changed the 'datadir' property to my own path '/data'. When I ran the '/etc/init.d/mysqld start' command, mysql complained about the /data/mysql' directory not existing, but, it created it, nonetheless, and continued flawlessly. It never complained about anything since. I recommend the 'urpmi mysql' apparoach which saves a lot of time.

    BTW: The akonadi server uses a pre-existing mysql database. I had akonadi removed and manually deleted the default db because the 'urpmi' utility complained about a clash with the existing mysql-core package version which seems to be lower than the current mysql package needs. After installing the current mysql package version (5.1.42), I reinstalled akonadi and configured it to use my new mysql db. For this I used the desktop configuration tool advanced options (KDE). I worked fine with KDE without akonadi for a few days anyway. I'm not sure what's the use of akonadi on a single user laptop like mine.

    Copyright © 2009 virtualinfocom All rights reserved. Theme by Games. | animation Ani2Pix.