The default session time in php is until closing of browser
What are the MySQL database files stored in system ?
PMA22:30
Data is stored in name.myd
Table structure is stored in name.frm
Index is stored in name.myi
Table structure is stored in name.frm
Index is stored in name.myi
What are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()?
PMA22:29
mysql_fetch_array() -> Fetch a result row as a combination of
associative array and regular array.
mysql_fetch_object() -> Fetch a result row as an object.
mysql_fetch_row() -> Fetch a result set as a regular array().
mysql_fetch_object() -> Fetch a result row as an object.
mysql_fetch_row() -> Fetch a result set as a regular array().
What Is a Persistent Cookie?
PMA22:28
A persistent cookie is a cookie which is stored in a cookie file
permanently on the browser's computer. By default, cookies are created
as temporary cookies which stored only in the browser's memory. When the
browser is closed, temporary cookies will be erased. You should decide
when to use temporary cookies and when to use persistent cookies based
on their differences:
*Temporary cookies can not be used for tracking long-term information.
*Persistent cookies can be used for tracking long-term information.
*Temporary cookies are safer because no programs other than the browser can access them.
*Persistent cookies are less secure because users can open cookie files see the cookie values.
*Temporary cookies can not be used for tracking long-term information.
*Persistent cookies can be used for tracking long-term information.
*Temporary cookies are safer because no programs other than the browser can access them.
*Persistent cookies are less secure because users can open cookie files see the cookie values.
What function can be used to encode passwords for storage in the database
PMA04:44
The md5() function creates a one-way encoding of the
password.
php and pdf
PMA01:36
Declaring a Class
PMA01:33
To design your program or code library in an object-oriented
fashion, you'll need to define your own classes, using the class
keyword.
A class definition includes the class name and the properties and methods of the class. Class names are case-insensitive and must conform to the rules for PHP identifiers. The class name stdClass is reserved. Here's the syntax for a class definition:
A class definition includes the class name and the properties and methods of the class. Class names are case-insensitive and must conform to the rules for PHP identifiers. The class name stdClass is reserved. Here's the syntax for a class definition:
class classname [ extends baseclass ] { [ var $property [ = value ]; ... ] [ function functionname (args) { // code } ... ] }
Declaring Methods
A method is a function defined inside a class. Although PHP
imposes no special restrictions, most methods act only on data within the object
in which the method resides. Method names beginning with two underscores (_
_) may be used in the future by PHP (and are currently used for the object
serialization methods _ _sleep( ) and _ _wakeup( ), described
later in this chapter, among others), so it's recommended that you do not begin
your method names with this sequence.
Within a method, the $this variable contains a
reference to the object on which the method was called. For instance, if you
call $rasmus->birthday( ) inside the birthday( ) method,
$this holds the same value as $rasmus. Methods use the
$this variable to access the properties of the current object and to
call other methods on that object.
Here's a simple class definition of the Person class
that shows the $this variable in action:
class Person {
var $name;
function get_name ( ) {
return $this->name;
}
function set_name ($new_name) {
$this->name = $new_name;
}
}
As you can see, the get_name( ) and set_name(
) methods use $this to access and set the $name property
of the current object.
To declare a method as a static method, use the static keyword.
Inside of static methods the variable $this is not defined. For
example:
class HTML_Stuff {
static function start_table( ) {
echo "<table border='1'>\n";
} static function end_table ( ) {
echo "</table>\n";
}
}
HTML_Stuff::start_table( ); // print HTML table rows and columns HTML_Stuff::end_table( );
Declaring Properties
In the previous definition of the Person class, we
explicitly declared the $name property. Property declarations are
optional and are simply a courtesy to whoever maintains your program. It's good
PHP style to declare your properties, but you can add new properties at any
time.
Here's a version of the Person class that has an
undeclared $name property:
class Person { function get_name ( ) { return $this->name; } function set_name ($new_name) { $this->name = $new_name; } }
You can assign default values to properties, but those default
values must be simple constants:
var $name = 'J Doe'; // works var $age = 0; // works var $day = 60*60*24; // doesn't work
Using access modifiers, you can change the visibility of
properties. Properties that are accessible outside the object's scope should be
declared public; properties on an instance that can only be accessed by
methods within the same class should be declared private.
Sorting One Array at a Time
PMA01:31
Effect
|
Ascending
|
Descending
|
User-defined order
|
---|---|---|---|
Sort array by values, then reassign indices starting with
0
|
sort( )
|
rsort( )
|
usort( )
|
Sort array by values
|
asort( )
|
arsort( )
|
uasort( )
|
Sort array by keys
|
ksort( )
|
krsort( )
|
uksort( )
|
The sort( ), rsort( ), and usort( )
functions are designed to work on indexed arrays because they assign new numeric
keys to represent the ordering. They're useful when you need to answer questions
such as, "What are the top 10 scores?" and "Who's the third person in
alphabetical order?" The other sort functions can be used on indexed arrays, but
you'll only be able to access the sorted ordering by using traversal functions
such as foreach and next
To sort names into ascending alphabetical order, you'd use
this:
$names = array('cath', 'angela', 'brad', 'dave'); sort($names); // $names is now 'angela', 'brad', 'cath', 'dave'
To get them in reverse alphabetic order, simply call rsort(
) instead of sort( ).
If you have an associative array mapping usernames to minutes
of login time, you can use arsort( ) to display a table of the top
three, as shown here:
$logins = array('njt' => 415, 'kt' => 492, 'rl' => 652, 'jht' => 441, 'jj' => 441, 'wt' => 402); arsort($logins); $num_printed = 0; echo("<table>\n"); foreach ($logins as $user => $time ) { echo("<tr><td>$user</td><td>$time</td></tr>\n"); if (++$num_printed == 3) { break; // stop after three } } echo("</table>\n"); <table> <tr><td>rl</td><td>652</td></tr> <tr><td>kt</td><td>492</td></tr> <tr><td>jht</td><td>441</td></tr> </table>
ksort($logins); echo("<table>\n"); foreach ($logins as $user => $time) { echo("<tr><td>$user</td><td>$time</td></tr>\n"); } echo("</table>\n"); <table> <tr><td>jht</td><td>441</td></tr> <tr><td>jj</td><td>441</td></tr> <tr><td>kt</td><td>492</td></tr> <tr><td>njt</td><td>415</td></tr> <tr><td>rl</td><td>652</td></tr> <tr><td>wt</td><td>402</td></tr> </table>
User-defined ordering requires that you provide a function that
takes two values and returns a value that specifies the order of the two values
in the sorted array. The function should return 1 if the first value is
greater than the second, -1 if the first value is less than the second,
and 0 if the values are the same for the purposes of your custom sort
order.
a program that lets you try the various sorting functions on the same
data.