SELECTING DATA IN PHP

You frequently select data in a MySQL table using PHP. Selecting data through a PHP program
using a MySQL command takes four steps:
1. Make a connection to the database.
2. Create a safe query with the command.
3. Run the query.
4. Read the results.
The following code makes the connection and creates a safe query. Rather than just running the
query, use it as the right side of an assignment. This creates a mysqli_result object that you use to
read the results via methods in the result object. This example takes each row, one at a time,
and puts it into an associative array.


<?php
define(“MYSQLUSER”, “php24sql”);
define(“MYSQLPASS”, “hJQV8RTe5t”);
define(“HOSTNAME”, “localhost”);
define(“MYSQLDB”, “test”);
// Make connection to database
$connection = @new mysqli(HOSTNAME, MYSQLUSER, MYSQLPASS, MYSQLDB);
if ($connection->connect_error) {
die(‘Connect Error: ‘ . $connection->connect_error);
} else {
echo ‘Successful connection to MySQL <br />’;
// Set up the query
$query = “SELECT * FROM ‘table1‘ “
. “ WHERE ‘code‘ = 15”
. “ ORDER BY ‘description‘ ASC “
;
// Run the query
$result_obj = ‘’;
$result_obj = $connection->query($query);
// Read the results
// loop through the result object, row by row
// reading each row into an associative array
while($result = $result_obj->fetch_array(MYSQLI_ASSOC)) {
// display the array
print_r($result);
echo ‘<br />’;
}
}

// Read the results
// loop through the results, row by row
// reading each row into an associative array
while($result = $result_obj->fetch_array(MYSQLI_ASSOC)) {
// collect the array
$item[] = $result;
}
// print array when done
echo ‘<pre>’;
print_r($item);
echo ‘</pre>’;


The example prints out the array









fetch_array(MYSQLI_ASSOC): This returns an associative array. Loop through to get all the
rows. Same as fetch_assoc().
‰ fetch_array(MYSQLI_NUM): This returns a numeric array. Loop through to get all the rows.
Same as fetch_row().
‰ fetch_array(MYSQLI_BOTH): This returns both an associative array and a numeric array
with the same data. Loop through to get all the rows. This is the default if no type is
specifi ed.
‰ fetch_all(MYSQLI_ASSOC): This returns all the rows as an associative array.
‰ fetch_all(MYSQLI_NUM): This returns all the rows as a numeric array.
‰ fetch_all(MYSQLI_BOTH): This returns all the rows both as an associative array and a
numeric array with the same data.
‰ fetch_object($class_name): This returns an object of the row. Loop through to get all
the rows. If you give it a class name, it uses that class to create the object. If there is no class
name it will create a stdClass object, which is a predefi ned class.

Optimizing for Both Facebook and Search Engines

You’re probably familiar with search engine optimization (SEO) tactics for improving your website’s
search rankings in Google and other major search engines. But have you thought about how to incorporate
social media into your search strategy?
Facebook can be a valuable asset for search results. The volume of content and variety of places to add
keyword-rich content can help you attract new Page members on Facebook, while providing more natural
search results
Facebook is indexed by search engines and also has deals with Google
and Bing to display social search results that include posts from your friends.
Facebook’s search is not always the greatest at displaying results, but the site’s working on it.
Counteract its shortcomings with some rockstar SEO to ensure that people looking for your name or
service can find you. Misspellings are especially important to account for on Facebook.
In the more general natural-search realm, a well-optimized Facebook Page can help you overtake
a competitor by providing a second set of Pages (in addition to your own website) to display on the
search results page. This can also be helpful when you’re looking to do some reputation management.
A Facebook Page can also give you the opportunity to add a few more keywords that didn’t work as
well on your website..

Developing a Facebook Content Strategy

Given the restrictions Facebook places on Page design, content is the easiest—and often most
effective—
way to differentiate yourself from competitors. Facebook’s power lies in its huge number
of users, but this also creates a high volume of posts. To reach these potential customers or brand
enthusiasts, your content must stand apart from the rest. Because content is a core piece of a successful
Facebook marketing campaign, this chapter explores ways you can create and optimize it for
Page members, while at the same time improving your placement in both Facebook and natural web
searches.

Competing with Other Content on Facebook
The average Facebook user has 130 friends and is connected to 80 community Pages, Groups, and
Events. Yet this is only a fraction of the 900 million people, places, and things that he could interact with
on Facebook

Considering the more than 30 billion pieces of content being shared across
the site each month, you can understand clearly why content is a key factor in your Facebook marketing
strategy. Obviously, there’s a lot that the average user is seeing on a daily basis. But this average user
also creates about 90 pieces of content every month—posting links to news stories or blog posts, writing
notes, uploading to photo albums, creating Events, writing on friends’ Walls, and more.

Since Facebook imposes so many design restrictions, content is the best way to market yourself to
potential Page members (and future customers), as well as to keep current Page members and customers
engaged and entertained. On the other hand, you must also combat the fatigue many users feel at
seeing a never-ending stream of their friends’ lunch orders, random thoughts, and recent likes.

What Is a Session?

It is stored at server side because PHP is server side scripting language

Session is stored on server side because how much time page will execute it doesn't depend on client it depends on server. Server decide the session of each page ..thats why session is stored on server side

Session is to store as the server side value
method $_session start('id');
and cookie is store the validation of client side

How do you define a constant in php?

by define() directive,
like define (“MYCONSTANT”, 500);

THE DIFFERENT TYPES OF ERRORS IN PHP?

1. Notices: These are trivial, non-critical errors that PHP encounters while executing a script – for example, accessing a variable that has not yet been defined
2. Warnings: These are more serious errors – for example, attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination.
3. Fatal errors: These are critical errors – for example, instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP’s default behavior is to display them to the user when they take place.
Internally, these variations are represented by twelve different error types

What’s the special meaning of __sleep and __wakeup?

__sleep returns the array of all the variables than need to be saved,
while __wakeup retrieves them.

What is the difference between $age and $$age

They are both variables. But $age is a variable with a fixed name. $$age is a variable who’s name is stored in $age. For example, if $age contains “var”, $$age is the same as $var.

$test = ‘abcd';
is equivalent to
$holder = ‘test';
 $$holder = ‘abcd';

How many values can the SET function of MySQL take?

MySQL set can take zero or more values but at the maximum it can
take 64 values

What is the maximum size of a file that can be uploaded using PHP and how can we change this?

By default the maximum size is 2MB.
 can change the size
 setup at php.ini
upload_max_filesize = 12M