<?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>PersonalBlog &#187; PHP</title>
	<atom:link href="http://arimita.web.id/category/it/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://arimita.web.id</link>
	<description>Just another personal weblog</description>
	<lastBuildDate>Mon, 19 Jul 2010 08:31:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Working with Files</title>
		<link>http://arimita.web.id/2010/06/working-with-files/</link>
		<comments>http://arimita.web.id/2010/06/working-with-files/#comments</comments>
		<pubDate>Sun, 06 Jun 2010 02:29:33 +0000</pubDate>
		<dc:creator>mythworks</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[append]]></category>
		<category><![CDATA[fclose]]></category>
		<category><![CDATA[feof]]></category>
		<category><![CDATA[fgetc]]></category>
		<category><![CDATA[fgets]]></category>
		<category><![CDATA[file PHP]]></category>
		<category><![CDATA[fileatime]]></category>
		<category><![CDATA[filesize]]></category>
		<category><![CDATA[file_get_contents]]></category>
		<category><![CDATA[fopen]]></category>
		<category><![CDATA[fputs]]></category>
		<category><![CDATA[fread]]></category>
		<category><![CDATA[lock_ex]]></category>
		<category><![CDATA[lock_sh]]></category>
		<category><![CDATA[lock_un]]></category>
		<category><![CDATA[read]]></category>
		<category><![CDATA[write]]></category>

		<guid isPermaLink="false">http://arimita.web.id/?p=210</guid>
		<description><![CDATA[We can do things for files like reading, writing or appending. Before we start with files, we must open it first for reading, writing or both. PHP provides the fopen() function for doing so. fopen() requires a string that contains the file path and the mode like read (r), write (w) and append (a). Let’s [...]]]></description>
			<content:encoded><![CDATA[<p>We can do things for files like reading, writing or appending. Before we start with files, we must open it first for reading, writing or both. PHP provides the fopen() function for doing so. fopen() requires a string that contains the file path and the mode like read (r), write (w) and append (a). Let’s see the example:</p>
<pre class="brush: php;">
&lt;?
$file='D:\xampp\htdocs\exprogram\filetxt\readme.txt';

	if (file_exists($file)){
		$of = fopen ($file, 'r');
		$read = fread ($of, filesize($file));
		echo $read.', panjang= ' .strlen($read);
		fclose($of);
	}
	else{
		echo 'The file is not exist';
	}
//eof
</pre>
<p>Function file_exists() is used for the existence of a file. If the file is found file_exists() return true, otherwise it returns false. Function fread() is for reading arbitrary amounts of data from a file through accept a file resource as an argument, as well as the number of bytes you want to read. Try to change line 6 above with $read = fread ($of, 10); then see the result. Assuming that all is well and you go on to work with your open file, you should remember to close it when you finish using fclose().</p>
<p><strong>Checking the status of a file:</strong><br />
After checking that a file exists, you can find out some things that you can do with it. PHP can help you typically whether you can read, write to or execute this file.<br />
is_readable() tells you whether you can read a file.<br />
is_writable() tells you whether you can write to a file.<br />
is_executable() tells you whether you can run a file, relying on either the file&#8217;s permissions or its extension depending on your platform.<br />
All above function requires the file path and returns a Boolean value.</p>
<p><strong>Getting date information about a file:</strong><br />
This function is used to find out when a file was last written to or accessed.<br />
fileatime() to find out when a file was last accessed.<br />
filemtime() to discover the modification date of a file.<br />
filectime() to test the change time of a document.<br />
Lets see the example:</p>
<pre class="brush: php;">
&lt;?
$file='D:\xampp\htdocs\exprogram\filetxt\readme.txt';
	$ftime = fileatime($file);
	echo $file. ‘ was last accessed on &quot;;
	echo date(‘D d M Y g:i A’, $ftime);
</pre>
<p><strong>Reading lines from a file:</strong><br />
To read a line from an open file you can use fgets(), which requires the file resource returned from fopen() as an argument like this:</p>
<pre class="brush: php;">
&lt;?
$file='D:\xampp\htdocs\exprogram\filetxt\readme.txt';
$of = fopen ($file, 'r');
	$line = fgets ($of);
	echo $line;
	fclose($of);
</pre>
<p>Although you can read lines with fgets(), you need some way to tell when you reach the end of the file. The feof() function does this by returning true when the end of the file has been reached and false otherwise. So you have enough information to read a file line by line as shown below:</p>
<pre class="brush: php;">
&lt;?
$file='D:\xampp\htdocs\exprogram\filetxt\readme.txt';
$of = fopen ($file, 'r') or die (‘Could not open file’);
	while (!feof($of)){
		$line = fgets($of, 10);
		echo $line;
}
</pre>
<p><strong>Moving around a file:</strong><br />
Function fseek() let you decide the position manually from which the acquisition begins. fseek() enable you to change your current position within a file. It requires a file resource and an integer that represents the offset from the start of the file (in bytes) to which you want to jump. Lets see the example below:</p>
<pre class="brush: php;">
&lt;?
$file='D:\xampp\htdocs\exprogram\filetxt\readme.txt';
$of = fopen ($file, 'r') or die (‘Could not open file’);
	$fsize = filesize($file);
	$fhalf = (int)($fsize/2);
	Echo ‘Setengah file’. $fhalf;

	fseek($of, $fhalf);
	$ branch = fread($of, ($fsize - $fhalf));
	echo $branch;
</pre>
<p><strong>Reading characters from a file:</strong><br />
With use fgetc() it return only a single character from a file every time it is called. Because a character is always one byte in size, fgetc() doesn’t require a length argument. </p>
<pre class="brush: php;">
&lt;?
$file='D:\xampp\htdocs\exprogram\filetxt\readme.txt';
$of = fopen ($file, 'r') or die (‘Could not open file’);
	while (!eof($of)){
		$char = fgetc($of);
		echo $char.’&lt;br&gt;’;
}
</pre>
<p><strong>Reading entire file:</strong><br />
We can also read a file at one time use file_get_contents(). Lets take a look:</p>
<pre class="brush: php;">
&lt;?
$file='D:\xampp\htdocs\exprogram\filetxt\readme.txt';
$of = fopen ($file, 'r') or die (‘Could not open file’);
	$files = file_get_contents($file);
	echo $files;
</pre>
<p>That code will read entire file $file and saved into $files. But be careful if the size of file is very big :d.</p>
<p><strong>Writing or Appending to a file:</strong><br />
Writing occurs from the start of the file, any prior content is destroyed and replaced by the data you write. You use mode argument ‘w’ when you call fopen().</p>
<pre class="brush: php;">
&lt;?
$file='D:\xampp\htdocs\exprogram\filetxt\readme.txt';
$of= fopen($file, ‘w’) or die (‘Could not open file’);
fwrite($of,’Hello World \n’);
fclose($of);
</pre>
<p>Appending are added the writes to the existing file. But if you have nonexistent file, the file will be created first.</p>
<pre class="brush: php;">
&lt;?
$file='D:\xampp\htdocs\exprogram\filetxt\readme.txt';
$of= fopen($file,’a’) or die (‘Could not open file’);
fputs($of, ’and another thing \n’);
fclose($of);
</pre>
<p><strong>Locking files:</strong><br />
To locking files we can use flock() which locks a file to warn other processes against writing to or reading file while the current process is working with file. I mean you don’t need your file being corrupt because other user accessing files at the time. You should call flock() directly after calling fopen() and call it again to release the lock before closing the file. If the lock is not released, you will not be able to read or write to that file.</p>
<pre class="brush: php;">
&lt;?
$file='D:\xampp\htdocs\exprogram\filetxt\readme.txt';
	$of = fopen($file, ‘a’) or die (‘Could not open file’);
	flock($of, LOCK_EX); // exclusive lock
		// read or write to the file
	flock($of, LOCK_UN); // release the lock
	fclose($of);
</pre>
<p>There is another constant with type shared that is LOCK_SH. This type allows other processes to read the file but prevent writing (used when reading a file).  </p>
]]></content:encoded>
			<wfw:commentRss>http://arimita.web.id/2010/06/working-with-files/feed/</wfw:commentRss>
		<slash:comments>165</slash:comments>
		</item>
		<item>
		<title>Working with MySQL Database</title>
		<link>http://arimita.web.id/2010/04/working-with-mysql-database/</link>
		<comments>http://arimita.web.id/2010/04/working-with-mysql-database/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 00:44:12 +0000</pubDate>
		<dc:creator>mythworks</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[insert update delete mysql]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql database]]></category>
		<category><![CDATA[mysql_query]]></category>
		<category><![CDATA[php mysql]]></category>

		<guid isPermaLink="false">http://localhost/wp/?p=127</guid>
		<description><![CDATA[In this chapter we will try to run the basic SQL queries using mysql_query() function. Throught this function we can inserting, selecting, updating, deleting and retrieving data all. For INSERT, SELECT, UPDATE, and DELETE, no additional scripting is required after the query has been executed because you&#8217;re not displaying any results (unless you want to). [...]]]></description>
			<content:encoded><![CDATA[<p>In this chapter we will try to run the basic SQL queries using mysql_query() function. Throught this function we can inserting, selecting, updating, deleting and retrieving data all. For INSERT, SELECT, UPDATE, and DELETE, no additional scripting is required after the query has been executed because you&#8217;re not displaying any results (unless you want to). For SELECT, you have a few options for displaying the data retrieved by your query. But first you need create tabel in Database that we have been create before. As a sample I&#8217;m create table Person with some field like this:</p>
<pre class="brush: sql;"> CREATE TABLE `person` (
  `id` int(5) NOT NULL auto_increment,
  `lastname` varchar(15) collate latin1_general_ci NOT NULL,
  `firstname` varchar(15) collate latin1_general_ci NOT NULL,
  `address` varchar(25) collate latin1_general_ci NOT NULL,
  `city` varchar(20) collate latin1_general_ci NOT NULL,
  `age` int(2) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=7 ;
</pre>
<p>And now we learning Basic SQL Command to create and manipulate MySQL database tables.<br />
<strong>THE INSERT:</strong><br />
The simple code for adding new records is syntax like this:</p>
<pre class="brush: sql;">
INSERT INTO table_name (column list) VALUES (column values)
</pre>
<p><strong>The SELECT:</strong><br />
We used this command is to retrieve records. This command syntax can be totally simplistic or very complicated.</p>
<pre class="brush: sql;"> SELECT expressions_and_columns FROM table_name
 [WHERE some_condition_is_true]
 [ORDER BY some_column [ASC | DESC]]
 [LIMIT offset, rows]
</pre>
<p>One handy expression is the * symbol, which stands for &#8220;everything.&#8221; So, to select &#8220;everything&#8221; mean all rows/ all columns. </p>
<p><strong>THE UPDATE:</strong><br />
Update is used to modify the contents of one or more columns in an wxisting record. Basic update syntax is look like:</p>
<pre class="brush: sql;"> UPDATE table_name
 SET column_name='new value'
 [WHERE some_condition_is_true]</pre>
<p>The guidelines for updating a record are similar to those used when inserting a record—the data you&#8217;re entering must be appropriate to the data type of the field, and you must enclose your strings in single or double quotes, escaping where necessary.</p>
<p><strong>THE DELETE:</strong><br />
This command is used to remove specification column. And the basic syntax is look like:</p>
<pre class="brush: sql;"> DELETE FROM table_name
 [WHERE some_condition_is_true]
 [LIMIT rows]
</pre>
<p>You have learned the basic of SQL, from tabel creation to manipulating records. See you in the next chapter.</p>
]]></content:encoded>
			<wfw:commentRss>http://arimita.web.id/2010/04/working-with-mysql-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Connecting to MySQL with PHP</title>
		<link>http://arimita.web.id/2010/04/33/</link>
		<comments>http://arimita.web.id/2010/04/33/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 02:02:29 +0000</pubDate>
		<dc:creator>mythworks</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[connecting mysql]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql database]]></category>
		<category><![CDATA[mysql_connect]]></category>

		<guid isPermaLink="false">http://localhost/wp/?p=33</guid>
		<description><![CDATA[To connecting MySQL Database, make sure you have MySQL running at a location to which your Web server can connect. Then you have created a user, password and the database to which you want to connect. The mysql_connect() is the first function in PHP to connect to MySQL.
The basic syntax for the connection is:
 mysql_connect(&#34;hostname&#34;, [...]]]></description>
			<content:encoded><![CDATA[<p>To connecting MySQL Database, make sure you have MySQL running at a location to which your Web server can connect. Then you have created a user, password and the database to which you want to connect. The mysql_connect() is the first function in PHP to connect to MySQL.<br />
The basic syntax for the connection is:</p>
<pre class="brush: php;"> mysql_connect(&quot;hostname&quot;, &quot;username&quot;, &quot;password&quot;);</pre>
<p>Using actual sample values, the connection function looks like this:</p>
<pre class="brush: php;"> mysql_connect(&quot;localhost&quot;, &quot;root&quot;, &quot;pass&quot;);</pre>
<p>This function returns a connection index (connection is succesful) or return false (connection fails). Lets see a working example of a connection script below. It assign the value of the connection index to a variable called $conn, then prints the value of $conn as proff of a connection. If you are not using password, just empty the password variable.</p>
<pre class="brush: php;">
&lt;?php
$host=&quot;localhost&quot;;
$user=&quot;root&quot;;
$pass=&quot;&quot;;
$conn=mysql_connect($host, $user, $pass);
echo &quot;$conn&quot;;
//eof
</pre>
<p>Save this script as config.php (sometimes I save as config.inc), then place it on your work folder. Check the result on your web browser and you will see something like this:</p>
<pre class="one"> Resource id #2</pre>
<p>Connecting to MySQL using the mysql_connect() function is pretty straightforward. The connection closes when the script finishes its execution, but if you would like to explicitly close the connection, simply add the mysql_close() function at the end of the script.<br />
And now we will try to connecting a Database, using function called mysql_select_db() with the following syntax:</p>
<pre class="brush: php;"> mysql_select_db($db,$conn);
</pre>
<p>To connect to a database named test_conn, first use mysql_connect(), then use mysql_select_db(), like this:</p>
<pre class="brush: php;">
&lt;?php
$host=&quot;localhost&quot;;
$user=&quot;root&quot;;
$pass=&quot;&quot;;
$db=&quot;test_conn&quot;;
$conn=mysql_connect($host, $user, $pass);
mysql_select_db($db,$conn);
//eof
</pre>
<p>You can modified simple connection script above by adding error message. The mysql_error() function will return a helpful error message when there is a mistake. Don&#8217;t forget to insert conjunction  with the PHP die() function. See the modified script below:</p>
<pre class="brush: php;">
&lt;?php
  $host=&quot;localhost&quot;;
  $user=&quot;root&quot;;
  $pass=&quot;&quot;;
  $db=&quot;test_conn&quot;;
  $conn=mysql_connect($host, $user, $pass);
   if (!$conn){
       die('Could not connect Database.'.mysql_error());
   }
   mysql_select_db($db,$conn);
//eof
</pre>
<p>Move on to the next section to start inserting data into your table, and soon you&#8217;ll be retrieving and formatting it via PHP. Good Luck.</p>
]]></content:encoded>
			<wfw:commentRss>http://arimita.web.id/2010/04/33/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

