How to setup a web development environment

How to setup a web development environment

3 40465
How to setup a web development environment

How to setup a web development environment

Welcome to our first video tutorial. Where I’m going to show you in detail how to setup a local web development environment. This tutorial is for novices and beginner in web development. Most of us are using Windows systems, this is because I selected WAMP at the most appropriate tool for us. We will install WAMP at our computer, and I will show you how you can use your database (phpMyAdmin), and, as some extra – I will show you a process of making own php-based RSS feed (on PHP).

After you have finished this video, you can copy and test the code we have just made:

<?
// step 1 - we should connect to database and take all our records:
$vLink = mysql_connect('localhost', 'root', ''); // this is default username and password for WAMP
mysql_select_db('test_db', $vLink);
mysql_query('SET names UTF8'); // let's set UTF8 mode (in order to support unicode)
$sSQL = 'SELECT * FROM `stories` ORDER BY `id` DESC'; // this is our SQL query to take our records
$vRes = mysql_query($sSQL); // execution of query
$aStories = array(); // an empty array to collect stories (records)
if ($vRes) {
    while($aRow = mysql_fetch_array($vRes, MYSQL_ASSOC)) { // lets walk through all the records
        $aStories[] = $aRow;
    }
    mysql_free_result($vRes);
}
// check
// print_r($aStories); // well done
// step 2 - display data array as rss feed
$sFeeds = '';
foreach ($aStories as $aStory) { // let's walk through all the records again and prepare Items for RSS
    $sFeeds .= <<<EOF
<item>
    <guid><![CDATA[{$aStory['id']}]]></guid>
    <link><![CDATA[story.php?id={$aStory['id']}]]></link>
    <title><![CDATA[{$aStory['title']}]]></title>
    <description><![CDATA[{$aStory['description']}]]></description>
    <pubDate>{$aStory['when']}</pubDate>
</item>
EOF;
}
// now - we should prepare necessary header and output our RSS feed:
header('Content-Type: text/xml; charset=utf-8');
echo <<<EOF
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
    <channel>
        <title>Our own RSS feed</title>
        <link>http://localhost/feed.php</link>
        <description>Our own RSS feed</description>
        <lastBuildDate>2012-07-16 00:00:00</lastBuildDate>
        {$sFeeds}
    </channel>
</rss>
EOF;

download package

SIMILAR ARTICLES


3 COMMENTS

  1. I would suggest not to you mysql_* as it is deprecated. I think you should teach people either in PDO or mysqli prepared statements?

    • Hi Hassan,
      Do you think that ordinary mysql is obsolete? I do not completely agree with that. Mysql is still used in most websites.

Leave a Reply to tonyluffy Cancel reply