Working with MySQL

There are a number of RDBMS packages available. These programs vary in power,
flexibility, and price. However, they all work in essentially the same way.


  • It is a very powerful program in its own right. It handles a large subset of the functionality of the most expensive and powerful database packages.
  •  It uses a standard form of the well-known SQL data language.
  •  It is released under an open-source license.
  •  It works on many operating systems and with many languages.
  •  It works very quickly and works well even with large data sets.
  • PHP ships with a number of functions designed to support MySQL databases.

0 comments:

XML_RSS in PHP

RSS (RDF Site Summary, Really Simple Syndication) feeds are a common use
of XML. RSS is an XML vocabulary to describe news items, which can then be
integrated (also called content syndication) into your own web site. PHP.net
has an RSS feed with the latest news items at http://www.php.net/news.rss.
You can find the dry specs of the RSS specification at http://web.resource.org/
rss/1.0/spec, but it’s much better to see an example. Here is part of the RSS file
we’re going to parse:

<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
>
<channel rdf:about="http://www.php.net/">
<title>PHP: Hypertext Preprocessor</title>
<link>http://www.php.net/</link>
<description>The PHP scripting language web site</description>
<items>
<rdf:Seq>
<rdf:li rdf:resource="http://qa.php.net/" />
<rdf:li rdf:resource="http://php.net/downloads.php" />
</rdf:Seq>
</items>
</channel>
<!-- RSS-Items -->
<item rdf:about="http://qa.php.net/">
<title>PHP 4.3.5RC1 released!</title>
<link>http://qa.php.net/</link>
<description>PHP 4.3.5RC1 has been released for testing. This is
➥the first release candidate and should have a very low number
➥of problems and/or bugs. Nevertheless, please download and test
➥it as much as possible on real-life applications to uncover any
➥remaining issues. List of changes can be found in the NEWS
➥file.</description>
<dc:date>2004-01-12</dc:date>
</item>
<item rdf:about="http://www.php.net/downloads.php">
<title>PHP 5.0 Beta 3 released!</title>
<link>http://www.php.net/downloads.php</link>
<description>PHP 5.0 Beta 3 has been released. The third beta of
➥PHP is also scheduled to be the last one (barring unexpected
➥surprises). This beta incorporates dozens of bug fixes since
➥Beta 2, better XML support and many other improvements, some
➥of which are documented in the ChangeLog. Some of the key
➥features of PHP 5 include: PHP 5 features the Zend Engine 2.
➥XML support has been completely redone in PHP 5, all
➥extensions are now focused around the excellent libxml2
➥library (http://www.xmlsoft.org/). SQLite has been bundled
➥with PHP. For more information on SQLite, please visit their
➥website. A new SimpleXML extension for easily accessing and
➥manipulating XML as PHP objects. It can also interface with
➥the DOM extension and vice-versa. Streams have been greatly
➥improved, including the ability to access low-level socket
➥operations on streams.<description><dc:date>2003-12-21<
➥dc:date>
</item>
<!-- / RSS-Items PHP/RSS -->
</rdf:RDF>

This RSS files consists of two parts: the header, describing the site from
which the content is syndicated, and a list of available items. The second part
consists of the news items. We don’t want to refetch the RSS file from http://
php.net every time a user visits a page that displays this information. Thus,
we’re going to add some caching. Downloading the file once a day should be
sufficient because news isn’t updated more often than daily. (On php.net, other
sites might have different policies.)

We’re going to use the PEAR::XML_RSS class that we installed with pear
install XML_RSS. Here is the script:

<?php
require_once "XML/RSS.php";
$cache_file = "/tmp/php.net.rss";

First, as shown previously, we include the PEAR class and define the location
of our cache file:

if (!file_exists($cache_file) ||
(filemtime($cache_file) < time() - 86400))
{
copy("http://www.php.net/news.rss", $cache_file);
}

Next, we check whether the file has been cached before and whether the
cache file is too old (86,400 seconds is one day). If it doesn’t exist or is too old,
we download a new copy from php.net and store it in the cache file:

$r =& new XML_RSS($cache_file);
$r->parse();

We instantiate the XML_RSS class, passing our RSS file, and call the
parse() method. This method parses the RSS file into a structure that can be
fetched by other methods, such as getChannelInfo() that returns an array containing
the title, description, and link of the web site, as shown here:

array(3) {
["title"]=>
string(27) "PHP: Hypertext Preprocessor"
["link"]=>
string(19) "http://www.php.net/"
["description"]=>
string(35) "The PHP scripting language web site"
}

getItems() returns the title, description, and link of the news item. In the
following code, we use the getItems() method to loop over all items and display
them:

foreach ($r->getItems() as $value) {
echo strtoupper($value['title']). "\n";
echo wordwrap($value['description']). "\n";
echo "\t{$value['link']}\n\n";
}
?>

When you run the script, you will see that it outputs the news items from
the RSS file:

PHP 4.3.5RC1 RELEASED!
PHP 4.3.5RC1 has been released for testing. This is the first release
candidate and should have a very low number of problems and/or bugs.
Nevertheless, please download and test it as much as possible on real-life
applications to uncover any remaining issues. List of changes can be found
in the NEWS file.
http://qa.php.net/

PHP 5.0 BETA 3 RELEASED!
PHP 5.0 Beta 3 has been released. The third beta of PHP is also
scheduled to be the last one (barring unexpected surprises). This
beta incorporates dozens of bug fixes since Beta 2, better XML
support and many other improvements, some of which are documented in
the ChangeLog. Some of the key features of PHP 5 include: PHP 5
features the Zend Engine 2. XML support has been completely redone in
PHP 5, all extensions are now focused around the excellent libxml2
library (http://www.xmlsoft.org/). SQLite has been bundled with PHP.
For more information on SQLite, please visit their website. A new
SimpleXML extension for easily accessing and manipulating XML as PHP
objects. It can also interface with the DOM extension and vice-versa.
Streams have been greatly improved, including the ability to access
low-level socket operations on streams.

0 comments:

Dynamic Programming


 Dynamic programming is a method for solving complex problems in maths and computer science in which large problems are broken down into smaller problems.

Through solving the individual smaller problems, the solution to the larger problem is discovered.

Stage – division of sequence of a system into various sub parts is called stages
State – a specific measurable condition of the system
Recursive equation – at every stage in dynamic programming the decision rule is determined by evaluating an objective function called recursive equation

Principle of optimality – it states that an optimal set of decisions rules has the property that regardless of the ith decisions, the remaining decisions must be optimal with respect to the outcome that results from the ith decision. This means that optimal immediate decision depends only on current state and not how you got there

The two basic approaches for solving dynamic programming are

  • Backward recursion
  • Forward recursion 
Backward Recursion

  • It is a schematic representation of a problem involving a sequence of n decisions
  • Then dynamic programming decomposes the problem into a set of n stages of analysis, each stage corresponding to one of the decisions. each stage of analysis is described by a set of elements decision, input state, output state and returns.

Forward Recursion 
  • This approach takes a problem decomposed into a sequence of n stages and analyzes the problem starting with the first stage in the sequence, working forward to the last stage it is also known as deterministic probability approach
Advantages

  • the process of breaking down a complex problem into a series of interrelated sub problems often provides insight into the nature of problem
  • Because dynamic programming is an approach to optimization rather than a technique it has flexibility that allows application to other types of mathematical programming problems
  • The computational procedure in dynamic programming allows for a built in form of sensitivity analysis based on state variables and on variables represented by stages
  • Dynamic programming achieves computational savings over complete enumeration.

Disadvantages

  • more expertise is required in solving dynamic programming problem then using other methods
  • lack of general algorithm like the simplex method. It restricts computer codes necessary for inexpensive and widespread use

Video




0 comments:

Copyright © 2012 OpenTechZone | Kesari Technologies |