<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Albert Maranian on Web &#187; PHP</title>
	<atom:link href="http://www.devbeans.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.devbeans.com</link>
	<description>My so-called Playground</description>
	<lastBuildDate>Thu, 15 Oct 2009 16:58:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Google Book Search API with Code Igniter</title>
		<link>http://www.devbeans.com/2009/06/google-book-search-api-with-code-igniter/</link>
		<comments>http://www.devbeans.com/2009/06/google-book-search-api-with-code-igniter/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 03:46:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Code Igniter]]></category>
		<category><![CDATA[Google Book API]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.devbeans.com/?p=88</guid>
		<description><![CDATA[I was working on a project, an e-commerce site where you can buy and/or sell books online. Selling  was a bit simple, students can add books by entering the ISBN and get its information from an API and for this, I was asked to use Amazon API. I spent a couple of hours, maybe a [...]]]></description>
			<content:encoded><![CDATA[<p>I was working on a project, an e-commerce site where you can buy and/or sell books online. Selling  was a bit simple, students can add books by entering the ISBN and get its information from an API and for this, I was asked to use Amazon API. I spent a couple of hours, maybe a whole day trying to figure out why the sample codes i was testing won&#8217;t work. Then i learned that Amazon API (Alexa Web Search) was shut down by Amazon itself, that&#8217;s why it&#8217;s not returning any results. And so we decided to use google book api instead. Below is the code on how to retrieve some book information by ISBN using code igniter and zend framework through the google book api:</p>
<pre class="php" name="code">
// This code is a method in my controller
// and called through ajax(using jquery)
// and returns result in json format

// I also created a library so i can easily load the
// zend framework and attain a neat code as possible

$isbn = $this->input->post("isbn");

// we need to first load the zend
// library, specifically the Books library
$this->load->library('zend', 'Zend/Gdata/Books');
$this->zend->load('Zend/Gdata/Books');

// create new instance of the zend books object
$books = new Zend_Gdata_Books();

// we will query book information by passing a
// query string to google api which looks like this
// http://books.google.com/books?isbn:0738531367

$query = $books->newVolumeQuery();
$query->setQuery("isbn:$isbn");

// the code below invokes
// the query and gets the result
$feed = $books->getVolumeFeed($query);

// this is a flag, so obviously when no result is returned,
// 0 will trigger that on my front end
$data['result'] = "0";
foreach ($feed as $entry):

    // some entry was found
	$data['result'] = "1";
    // some of the entry results are returned through
    // an array object, so to easily extract

    // just implode it and separate by a
    // character, in my case i used a comma(,)
	$data['authors'] = implode(", ",$entry->getCreators());
	$data['description'] = implode(", ",$entry->getDescriptions());
	$data['publishers'] = implode(', ',$entry->getPublishers());
	$data['identifiers'] = implode(', ',$entry->getIdentifiers());
	$data['category'] = implode(",", $entry->getSubjects());
	$data['book_title'] = $entry->getTitle()->text;
	$x = $entry->getThumbnailLink();
    // there are times that $entry->getThumbnailLink() returns
    // a null value, thus $x below is not an object
    // so use @ to escape possible errors in the codes below
    $data['book_image'] = @$x->href;
	$data['volume_id'] = $entry->getVolumeId();
	$data['year_published'] = implode(',' , $entry->getDates());
	$x = $entry->getFormats();
	$pages = @$x[0];
	$type = @$x[1];
	$data['pages']	= $pages->text;

	$x = $entry->getIdentifiers();
	$data['isbn10'] = str_replace("ISBN:", "",@$x[1]->text);
	$data['isbn13'] = str_replace("ISBN:", "",@$x[2]->text);

endforeach;		

// return result in json format
echo json_encode($data);
</pre>
<p>I will try to post soon on how to setup the Zend Framework library.</p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.devbeans.com/2009/06/google-book-search-api-with-code-igniter/" target="_blank"><img src="http://www.devbeans.com/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.devbeans.com/2009/06/google-book-search-api-with-code-igniter/" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.devbeans.com/2009/06/google-book-search-api-with-code-igniter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Session suddenly dies</title>
		<link>http://www.devbeans.com/2009/05/php-session-suddenly-dies/</link>
		<comments>http://www.devbeans.com/2009/05/php-session-suddenly-dies/#comments</comments>
		<pubDate>Tue, 12 May 2009 02:49:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP session dies]]></category>
		<category><![CDATA[PHP Session problem]]></category>
		<category><![CDATA[Request exceeded the limit of 10 internal redirects]]></category>

		<guid isPermaLink="false">http://www.devbeans.com/?p=84</guid>
		<description><![CDATA[Just a couple of days ago i was puzzled by what i thought was a PHP bug. I ran into a problem where when i open a page of the site i developed, the session that handles user login details dies. This usually happens when you fail to start the session, or maybe your session [...]]]></description>
			<content:encoded><![CDATA[<p>Just a couple of days ago i was puzzled by what i thought was a PHP bug. I ran into a problem where when i open a page of the site i developed, the session that handles user login details dies. This usually happens when you fail to start the session, or maybe your session timeout was set too short or you unnoticely unregistered the session somewhere before opening the page. I checked the PHP configuration file, and timeout was long enough for i have planned. Session was started on every page, including the page where it dies and i only have the intentional killing of the session on user logout. It took me a couple of days to try and solve the issue, where i reached the point that i have to backup session by a cookie, which i thought was a last option. It didn&#8217;t satisfy me, because using cookie will cause security issues at some point. So i took my chances and asked the help of my boss to look for all LAMP(Linux Apache MySQL PHP) related error logs.</p>
<p>As i scanned through the log files, i found this &#8220;<strong>Request exceeded the limit of 10 internal redirects due to probable configuration error. Use &#8216;LimitInternalRecursion&#8217; to increase the limit if necessary. Use &#8216;LogLevel debug&#8217; to get a backtrace.</strong>&#8220;. I googled for possible answers with regards to this error and later i found out that it has something to do with the rewrite module of apache where it keeps pointing to an unreachable destination/location maybe to a non-existing image, css file, or some media within the server. So then i checked my html and they were pointing all to existing locations, until i debugged my <strong>css file</strong> and found that i was referencing to an image that i <strong>FORGOT TO UPLOAD</strong>. Yes, an image caused this very pesky problem that in some point i thought of giving up on working with the project.</p>
<p>It took me over 3 days to figure out the problem(with the help of my boss of course).  It&#8217;s crazy to think how a very simple mistake could mess up everything. It&#8217;s very stressful to encounter problems which almost no one has encountered, but to be part of the few who have, i think it&#8217;s an honor to maybe help somebody who might encounter one in the future.</p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.devbeans.com/2009/05/php-session-suddenly-dies/" target="_blank"><img src="http://www.devbeans.com/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.devbeans.com/2009/05/php-session-suddenly-dies/" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.devbeans.com/2009/05/php-session-suddenly-dies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Neater way to write Control Structures in PHP</title>
		<link>http://www.devbeans.com/2008/10/a-neater-way-to-write-control-structures-in-php/</link>
		<comments>http://www.devbeans.com/2008/10/a-neater-way-to-write-control-structures-in-php/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 10:12:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.devbeans.com/?p=43</guid>
		<description><![CDATA[I am not a big fan of pre-built PHP sites or even CMS ready sites like joomla, drupal and the like which means almost all of the projects i have developed were coded from scratch using of course the best PHP Framework available,  Code Igniter.
Whatever programming language you maybe using(except i think the assembly language), [...]]]></description>
			<content:encoded><![CDATA[<p>I am not a big fan of pre-built PHP sites or even CMS ready sites like joomla, drupal and the like which means almost all of the projects i have developed were coded from scratch using of course the best PHP Framework available,  <a title="Code Igniter PHP Framework" href="http://www.codeigniter.com" target="_blank">Code Igniter</a>.</p>
<p>Whatever programming language you maybe using(<em>except i think the assembly language</em>), you&#8217;d probably have been using or used the control structures <strong>IF</strong>, <strong>FOR</strong>, <strong>WHILE</strong>, <strong>FOREACH </strong>etc&#8230; I have written several applications/websites using various programming languages and my favorite so far is VB 6.0 and VB.NET when it comes to control structures.</p>
<p>A simple VB IF statement would look this, which I call it the IF, THEN, ELSE structure:</p>
<pre class="vb" name="code">Dim MyNBATeam = "SUNS"

        If MyNBATeam &lt;&gt; "SUNS" Then
            MessageBox.Show("You're a Kobe lover")
            Me.Close()
        Else
            MessageBox.Show("Let's run and gun")
            FormX.Show()

        End If</pre>
<p>Neat eh? If we convert that to PHP normally we would do it like this:</p>
<pre class="php" name="code"> $my_nba_team = "SUNS";
 if ($my_nba_team == "SUNS"){
   echo "You're a Kobe lover";
   return;
 }
 else{
   echo "Let's run and gun";
   header("location: somepage.php");
}</pre>
<p>So to make PHP look like that of the VB structure let&#8217;s change that to this:</p>
<pre class="php" name="code"> $my_nba_team = "SUNS";
 if ($my_nba_team == "SUNS"):
    echo "You're a Kobe lover";
    return;
 else:
    echo "Let's run and gun";
    header("location: somepage.php");
 endif;</pre>
<p>Notice on how we eliminated the pesky curly braces? You probably have noticed that the opening curly brace({) was replaced by a colon(:) and the closing curly brace was replaced by endif; and remember also that when having compound statements inside your if and else, you don&#8217;t need to fence them with opening and curly braces. That will probably save you time when debugging nested IF&#8217;s.</p>
<p>You can also do the same thing with other control structures:</p>
<pre class="php" name="code">

//FOR LOOP
$odds = array();
$evens = array();
 for ($i=1; $i<50; $i++):
       if(!($i % 2)):
          array_push($evens, $i);
       else
          array_push($odds, $i);
       endif;
 endfor;

//WHILE LOOP

while ( 1 == 1 ):
     if (date("Y") == 2011 ):
         echo "I am getting, older";
         break;
     endif;
endwhile;

//FOREACH

foreach($teams->result() as $team):
    if($team->name == "SUNS"):
          echo "keep running";
          echo "BEAT L.A";
    endif;
endforeach;
</pre>
<p>It&#8217;s always nice to have a neatly written code, saves us time in the future and we will not give headaches to those who&#8217;s going to trace your code &#8211; in short, be a blessing. </p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.devbeans.com/2008/10/a-neater-way-to-write-control-structures-in-php/" target="_blank"><img src="http://www.devbeans.com/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.devbeans.com/2008/10/a-neater-way-to-write-control-structures-in-php/" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.devbeans.com/2008/10/a-neater-way-to-write-control-structures-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Working with MySQL Date and DateTime Data Type</title>
		<link>http://www.devbeans.com/2008/05/working-with-mysql-date-and-datetime-data-type/</link>
		<comments>http://www.devbeans.com/2008/05/working-with-mysql-date-and-datetime-data-type/#comments</comments>
		<pubDate>Tue, 13 May 2008 16:28:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.dodongonweb.com/?p=7</guid>
		<description><![CDATA[As a PHP developer, I have encountered projects that requires a manipulation of Date or DateTime field.  So here are some information and tips about dealing with Date and Datetime in MySQL with PHP:
MySQL Date Format:
MySQL is quite strict on the date format so you have to make sure that when you pass or [...]]]></description>
			<content:encoded><![CDATA[<p>As a PHP developer, I have encountered projects that requires a manipulation of Date or DateTime field.  So here are some information and tips about dealing with Date and Datetime in MySQL with PHP:</p>
<p><span style="color: #800000;"><strong>MySQL Date Format:</strong></span></p>
<p>MySQL is quite strict on the date format so you have to make sure that when you pass or reference a Date type field value be sure that the format is YYYY-MM-DD, for example 1984-05-18 for May 18, 1984. So if you want to insert a date value you may like to do it like this :</p>
<pre name="code" class="php">
$date = date("Y-m-d");
$sql = "INSERT INTO myTable(date_field) VALUES('$date')";
mysql_query($sql);
</pre>
<p>The above code obviously is very easy if the date you need is the current date. Now if you want to customize a date based on a user input you can perhaps do this:</p>
<pre name="code" class="php">
   $year = "2008";
   $month = "05";
   $day = "18";
   $the_raw_date = $year . "-". $month . "-" . $day;

   $date =  date("Y-m-d", strtotime($the_raw_date));
</pre>
<p>Now if you want to use the current date and add days, years or months you can do this:</p>
<pre name="code" class="php">
 $date_days_added = date("Y-m-d",0, 0, 0, date("m")  , date("d") + 7, date("Y"))); // adds 7 days to
current date
 $date_month_added = date("Y-m-d",0, 0, 0, date("m")  + 1 , date("d") , date("Y"))); // adds 1 month to current date
 $date_years_added = date("Y-m-d",0, 0, 0, date("m")  , date("d") , date("Y") + 2)); // adds 2 years to current date
</pre>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.devbeans.com/2008/05/working-with-mysql-date-and-datetime-data-type/" target="_blank"><img src="http://www.devbeans.com/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.devbeans.com/2008/05/working-with-mysql-date-and-datetime-data-type/" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.devbeans.com/2008/05/working-with-mysql-date-and-datetime-data-type/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

<!-- www.000webhost.com Analytics Code -->
<script type="text/javascript" src="http://analytics.hosting24.com/count.php"></script>
<noscript><a href="http://www.hosting24.com/"><img src="http://analytics.hosting24.com/count.php" alt="web hosting" /></a></noscript>
<!-- End Of Analytics Code -->
