Backup Your MySQL Database Contents to SQL File Using PHP

Here’s a snippet to backup MySQL database content to SQL file using PHP code. This code is very useful when you want to make a daily or hourly snapshot of your currently running database. Or maybe you want to add a backup feature on your blog CMS. backup_tables(‘localhost’,'username’,'password’,'blog’); /* backup the db OR just a table */ function backup_tables($host,$user,$pass,$name,$tables = ‘*’) { $link = mysql_connect($host,$user,$pass); mysql_select_db($name,$link); //get all of the Continue reading

Replace Multiple Backslash Character Using preg_replace() in PHP

It seems like an easy problem to solve, but It’s not as easy as it seems. Assuming I have this string in PHP: \\\super\\\\\\man\\\ and I would like to replace all the backslashes into space or other characters is not as easy as using str_replace() function. The number of backslashes may be 1 or more. But all consecutive need to be replace into ONE space.

Perfect Full Element Background Image With CSS3

An HTML element can have a background image. Normally we set it no-repeat, repeat-x, or repeat-y, regardless it is centered or x-y-positioned. There is time we may want it to be covered all over an element, regardless it’s size. Now, we can do this purely through CSS thanks to the background-size property now in CSS3. We’ll use the html element (better than body as it’s always at least the height Continue reading

File Handling in PHP: Read/Write To And From Text File

As a simple data storage alternative to Database Management System (e.g. MySQL) in PHP we can use plain text file. For example, a plain text file to store page counter information. Below is an example on how to store a simple string (text) into a text (.txt) file: <?php $data = ‘some text’; $fp = fopen(‘counter.txt’, ‘w’); if($fp) { fwrite($fp, $data); fclose($fp); } ?> Assuming a file named counter.txt exists Continue reading

Pemrograman Web PTIIK Genap 2012/2013: PHP File and Directory Handling

Update 21 Maret 2013: Contoh penanganan data dari form pada file dapat di-download. Berikut ini adalah slide presentasi pada pertemuan IV: PHP File and Directory Handling untuk mata kuliah Pemrograman Web semester Genap 2012/2013. Kelas yang diampu adalah kelas: Sistem Informasi A Sistem Informasi B Informatika A Hal-hal yang dibahas dalam pertemuan keempat mata kuliah ini mencakup penjelasan mengenai: File Handling Open and Closing File FIle Open Modes Read Data Opening Continue reading

Pemrograman Web PTIIK Genap 2012/2013: PHP Fundamentals

Update 19 Mar 2013: PHP companion files untuk sub-materi Session dan Cookie dapat di-download. Berikut ini adalah slide presentasi pada pertemuan III: PHP Fundamentals and State untuk mata kuliah Pemrograman Web semester Genap 2012/2013. Kelas yang diampu adalah kelas: Sistem Informasi A Sistem Informasi B Informatika A Hal-hal yang dibahas dalam pertemuan kedua mata kuliah ini mencakup penjelasan mengenai: Apache web server administration and configuration, PHP, and why PHP? Sistem and software Continue reading

Pemrograman Web: Tugas Pengganti Kuliah – Selasa 5 Maret 2013

Perkuliahan mata kuliah Pemrograman Web untuk kelas SI-A dan SI-B hari Selasa 5 Maret 2013 diberikan tugas pengganti perkuliahan dikarenakan saya selaku dosen pengampu mata kuliah tersebut ada tugas untuk mengajar di Universitas Brawijaya Kediri. Adapun tugas pengganti untuk mata kuliah tersebut hari Selasa 5 Maret 2013 adalah: Carilah sebuah permasalahan dan algoritma yang dapat menyelesaikan permasalahan tersebut (contoh: sort, search, perpangkatan, dll). Daftar pilihannya dapat dilihat di link ini, Continue reading

Communicating PHP with Android Java using JSON

When you have several variables (data) which you would send to Android using regular text on HTTP, then JSON would become an alternative format to XML. Android has it’s own JSON parser class which able to convert text on JSON format into a JSON Object. Since version 5.2.0, PHP has it’s built in json_encode() and json_decode() function to convert an array into json string and vice versa.