Doing, Learning, and Sharing

Try to be The Best

Dec
17
2009

PHP read CSV File and insert to Mysql DB

Simple code for read CSV File and insert into mysql database per rows.

following this code:

PHP:
  1. mysql_connect("localhost","root","admin");
  2.      mysql_select_db("contact");
  3.      $filename="data.csv";
  4.      $handle = fopen("$filename", "r");
  5.      while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
  6.      {
  7.        $import="INSERT into all_number(Name,Adress,Code) values('$data[0]','$data[1]','$data[2]')";
  8.        mysql_query($import) or die(mysql_error());
  9.       }
  10.      }
  11.      fclose($handle);
  12.    mysql_close();

I hope, This is helpfull for all

Jan
26
2009

Konfigurasi PHP pada Apache Web Server

Konfigurasi PHP Pada Apache Web Server

 

Sallam,

 

Saatnya berbagi pengalaman dan semoga bermanfaat bagi semua, mungkin bagi yang sudah jagoan ini adalah gampang dan hafal diluar kepala, namun sebaliknya mungkin juga bermanfaat bagi pemula yang sedang belajar Web dengan bahasa pemrograman PHP, dan Apache sebagai web servernya.

 

Sebelum Konfigurasi PHP dengan Apache kita lakukan, pastikan bahwa PHP dan Apache sudah terinstal di server.

Dalam hal ini PHP dan Apache yang aku gunakan adalah PHP 5.2.4 dan Apache 2.0 .

 

Untuk konfigurasi PHP dengan Apache kita mulai dengan file konfigurasi Apache 2.0, edit file httpd.conf milik apache, biasanya httpd.conf terdapat pada folder “conf\” dalam Path instalasi Apache.

Setelah di file httpd.conf terbuka, buat suatu remark yang menandakan lokasi penambahan fitur PHP dalam konfigurasi Apache, untuk memudahkannya, maka letakkan konfigurasi PHPnya pada bagian akhir dari konfigurasi apache.

Tambahkan script berikut pada file httpd.conf :

 

.[baris terakhir konfigurasi apache]

.

.

#Konfigurasi PHP

ScriptAlias /php/ "c:/php/"

AddType application/x-httpd-php .php

Action application/x-httpd-php "/php/php-cgi.exe"

 

Dalam script diatas, Path Instalasi PHP terletak pada “c:/PHP/”

 

Setelah meletakkan script diatas pada file httpd.conf, selanjutnya restart Apache Web Server, dan pastikan berjalan dengan lancar tanpa error saat restart Apache Web Servernya.

Buat file info.php pada lokasi htdocs (directory root Apache) yang isinya sebagai berikut:

 

<?

phpinfo();

?>

 

Selanjutnya open browser internet explorer, dan tuliskan alamat http://localhost/info.php

 

 

[caption id="attachment_70" align="alignnone" width="684" caption="forbidden"]forbidden[/caption]

 

Apabila muncul error seperti diatas, maka apache masih menutup akses untuk esekusi file PHP, dengan demikian kita harus merubah konfigurasi apache pada httpd.conf untuk akses file php. Berikut konfigurasi yang harus kita rubah,

 

<Directory />

    Options FollowSymLinks

    AllowOverride None

    Order deny,allow

    Deny from all

    Satisfy all

</Directory>

 

Menjadi

 

<Directory /> 

 

    Options FollowSymLinks

    AllowOverride None

    Order deny,allow

#  Deny from all

    Allow from all

    Satisfy all

</Directory>

 

Setelah merubah konfigurasi, restart Apache Web Servernya, lalu refresh web browser yang sebelumnya masih Forbidden.

 

[caption id="attachment_71" align="alignnone" width="749" caption="php version"]php version[/caption]

 

Maka akan muncul pada browser informasi tentang PHP Version 5.2.4

Dengan demikian konfigurasi PHP dengan Apache Web Server telah berhasil dilakukan.

 

Selamat Mencoba dan membuat sesuatu yang bermanfaat serta menyenangkan

 

Wasallam dan Terimakasih

 

 



Jan
24
2009

Belajar PHP

Mari kita belajar bahasa Pemrograman PHP.

 

Pertama kali yang harus di Install adalah program PHP nya sendiri, atau saya biasa bilang (PHP Console). Master PHPnya dapat di download pada situs http://www.php.net/downloads.php, situs tersebut selalu update versi terbaru.

Tata cara Instalasi biasanya selalu ada di dalam package download Master PHP.

 

Disini saya menggunakan Operating System Windows XP.

Setelah terInstal, kita test dengan pakai Command Prompt.

Misalnya, Directory install ada di C:\PHP\ , kita lakukan test memunculkan versi dari PHP, seperti dibawah ini ;

 

C:\PHP>php -v

PHP 5.2.4 (cli) (built: Aug 30 2007 07:06:31)

Copyright (c) 1997-2007 The PHP Group

Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

 

Untuk Menampilkan attribute dari command php, gunakan command php –help

 

C:\PHP>php --help

Usage: php [options] [-f] <file> [--] [args...]

       php [options] -r <code> [--] [args...]

       php [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...]

       php [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...]

       php [options] -- [args...]

       php [options] -a

 

  -a               Run interactively

  -c <path>|<file> Look for php.ini file in this directory

  -n               No php.ini file will be used

  -d foo[=bar]     Define INI entry foo with value 'bar'

  -e               Generate extended information for debugger/profiler

  -f <file>        Parse and execute <file>.

  -h               This help

  -i               PHP information

  -l               Syntax check only (lint)

  -m               Show compiled in modules

  -r <code>        Run PHP <code> without using script tags <?..?>

  -B <begin_code>  Run PHP <begin_code> before processing input lines

  -R <code>        Run PHP <code> for every input line

  -F <file>        Parse and execute <file> for every input line

  -E <end_code>    Run PHP <end_code> after processing all input lines

  -H               Hide any passed arguments from external tools.

  -s               Display colour syntax highlighted source.

  -v               Version number

  -w               Display source with stripped comments and whitespace.

  -z <file>        Load Zend extension <file>.

 

  args...          Arguments passed to script. Use -- args when first argument

                   starts with - or script is read from stdin

 

  --ini            Show configuration file names

 

  --rf <name>      Show information about function <name>.

  --rc <name>      Show information about class <name>.

  --re <name>      Show information about extension <name>.

  --ri <name>      Show configuration for extension <name>.

 

Dengan demikian PHP sudah dapat digunakan.

 

Tahapan I

 

Kita coba jalankan PHP file script,

Untuk penulisan syntac script PHP selalu diawali dengan <? atau <?php dan diakhiri dengan ?>.

Misalnya kita buat file coba.php

 

PHP:
  1. echo "Belajar cetak PHP";

 

Jalankan dengan PHP di command prompt;

 

C:\PHP>php coba.php

Belajar cetak PHP

C:\PHP>

 

Tahapan II

 

Tahapan II kita coba dengan memberikan masukan dari command prompt.

 

Nama File Coba2.php

PHP:
  1. // untuk menampilkan inputan
  2. fwrite(STDOUT, "Namamu Siapa: ");
  3. // Mengambil Data
  4. $nama = trim(fgets(STDIN));
  5. // Menampilan hasil Inputan
  6. fwrite(STDOUT, "Namamu , $nama! Kan");

 

Jalankan dengan PHP :

C:\PHP>php coba.php

Namamu Siapa: Socode

Namamu , Socode! Kan

C:\PHP>

 

Lanjut dengan mengkombinasikan masukan dengan kondisional.

Nama File coba3.php

PHP:
  1. fwrite(STDOUT, "Angka 1 : ");
  2. $angka1 = trim(fgets(STDIN));
  3. fwrite(STDOUT, "Angka 2 : ");
  4. $angka2 = trim(fgets(STDIN));
  5. if($angka1 == $angka2 ){
  6. fwrite(STDOUT, "Angka 1 dan 2 sama, yaitu $angka1");
  7. } else {
  8. fwrite(STDOUT, "Angka 1 dan 2 Tidak sama, \nyaitu angka 1= $angka1 dan angka 2= $angka2");
  9. }

Jalankan dengan PHP :

C:\PHP>php coba3.php

Angka 1 : 1

Angka 2 : 4

Angka 1 dan 2 Tidak sama,

yaitu angka 1= 1 dan angka 2= 4

 

Untuk Sementara Belajar cukup sampai disini.

Segera Update untuk tahap Selanjutnya.

 

Terimakasih.



Apr
10
2008

Setting RSS

Hahai.. iseng - iseng coba bikin RSS sendiri, dengan sedikit ber googling buat cari model dari xml rss,akhirnya jadi dech rss buatan sendiri.

Pake PHP, konek ke datasbase dengan sedikit utak atik bla..bla..bla.. Done sukses.

Nich aku sharing PHP Code rss sss(sangat sederhana sekale) :) :) :)

PHP:
  1. $conn = mysql_connect("XXXX","XXXXXXXXXXXXX","xxxxxXXxxx");
  2. mysql_select_db('ZAZAZAZA');
  3. $sql_query = "select post_title, guid, comment_count from wp_posts where post_type='post' order by post_date desc";
  4. $query = mysql_query($sql_query,$conn) or die("mampus dah ngonyeksi / query ne");
  5. $rxml = "<!--l version=\"1.0\-->\n";
  6. $rxml .= "\n";
  7. $rxml .= "\n";
  8. $rxml .= "\n";
  9. $rxml .= "Samid web site punya\n";
  10. $rxml .= " http://yurisdiansyah.org\n";
  11. while($obj = mysql_fetch_object($query)){
  12. $rxml .= "\n";
  13. $rxml .= "\n";
  14. $rxml .= "Posting dengan comment : ".$obj-&gt;comment_count."\n";
  15. $rxml .= " ".$obj-&gt;guid."\n";
  16. $rxml .= "\n";
  17. }
  18. mysql_close($conn);
  19. $rxml .= "\n";
  20. $rxml .= "";
  21. header("HTTP/1.1 200 OK");
  22. header("Content-Type: text/plain; charset=utf-8");
  23. echo $rxml;

copy script diatas di folder feed klo blum ada ya dibikin dulu, trus dikasih nama Index.php . Jika sudah semuanya sekarang lakukan testing.

Referensi rss xml model dari :

http://www.make-rss-feeds.com/

Selamat co-coba dan sukes :)

Powered by WordPress