Differences between INDEX, PRIMARY, UNIQUE, FULLTEXT in MySQL

Differences

  • KEY or INDEX refers to a normal non-unique index. Non-distinct values for the index are allowed, so the index may contain rows with identical values in all columns of the index. These indexes don’t enforce any restraints on your data so they are used only for making sure certain queries can run quickly.
  • UNIQUE refers to an index where all rows of the index must be unique. That is, the same row may not have identical non-NULL values for all columns in this index as another row. As well as being used to speed up queries, UNIQUE indexes can be used to enforce restraints on data, because the database system does not allow this distinct values rule to be broken when inserting or updating data.Your database system may allow a UNIQUE index to be applied to columns which allow NULL values, in which case two rows are allowed to be identical if they both contain a NULL value (the rationale here is that NULL is considered not equal to itself). Depending on your application, however, you may find this undesirable: if you wish to prevent this, you should disallow NULL values in the relevant columns.
  • PRIMARY acts exactly like a UNIQUE index, except that it is always named ‘PRIMARY’, and there may be only one on a table (and there should always be one; though some database systems don’t enforce this). A PRIMARY index is intended as a primary means to uniquely identify any row in the table, so unlike UNIQUE it should not be used on any columns which allow NULL values. Your PRIMARY index should be on the smallest number of columns that are sufficient to uniquely identify a row. Often, this is just one column containing a unique auto-incremented number, but if there is anything else that can uniquely identify a row, such as “countrycode” in a list of countries, you can use that instead.Some database systems (such as MySQL’s InnoDB) will store a table’s records on disk in the order in which they appear in the PRIMARY index.
  • FULLTEXT indexes are different from all of the above, and their behaviour differs significantly between database systems. FULLTEXT indexes are only useful for full text searches done with the MATCH() / AGAINST() clause, unlike the above three – which are typically implemented internally using b-trees (allowing for selecting, sorting or ranges starting from left most column) or hash tables (allowing for selection starting from left most column).Where the other index types are general-purpose, a FULLTEXT index is specialised, in that it serves a narrow purpose: it’s only used for a “full text search” feature.

Similarities

  • All of these indexes may have more than one column in them.
  • With the exception of FULLTEXT, the column order is significant: for the index to be useful in a query, the query must use columns from the index starting from the left – it can’t use just the second, third or fourth part of an index, unless it is also using the previous columns in the index to match static values. (For a FULLTEXT index to be useful to a query, the query must use all columns of the index.)

mySQL String Functions

Untuk mendapatkan result dimana jumlah char untuk field berkenaan adalah 2:

$sql = “SELECT field FROM table WHERE CHAR_LENGTH(field) = 2”

Selain penggunaa LIKE atau RLIKE, untuk mendapatkan result dimana 2 char pertama dlm field tersebut adalah Ah:

$sql = “SELECT field FROM table WHERE LEFT(field,2) = ‘Ah'”

Juga selain penggunaa LIKE atau RLIKE, untuk mendapatkan result dimana 2 char terakhir dlm field tersebut adalah ad:

$sql = “SELECT field FROM table WHERE RIGTH(field,2) = ‘ad'”

Untuk mendapatkan result dimana bermula char kedua sebanyak 3 char dlm field tersebut seperti hma:

$sql = “SELECT field FROM table WHERE MID(field,1,3) = hma'”

Sumber: mySQL.Com

Pemasangan Xampp

Hari ini masa PakCu agak terluang sedikit berbanding minggu-minggu sebelum ini. Jadi PakCu hendak mulakan pos-pos tutorial dengan tajuk Pemasangan Xampp. Terlebih dahulu PakCu nak terangkan mengenai peralatan yang perlu ada untuk menjalankan skrip-skrip PHP di dalam PC anda. Sebelum itu, sila lihat post berikut – http://www.haqis.com/?p=409


Keperluan Aplikasi

PHP adalah salah satu Server Side Scripting Programming Language selain daripada ASP, CMF, JSP, PERL, ROR. Untuk menjalankan skrip-skrip PHP di dalam PC anda, anda perlu melengkapkan PC anda dengan aplikasi-aplikasi berikut:
+ Web Server (apache, IIS,  lighttpdnginx, Cherokee dsbnya)
+ PHP (terkini versi 5.5)
+ Database (mysql, oracle, mssql, sybase, ODBC dsbnya)
+ Editor @ IDE  (Notepad++, sublime text, PHPStorm, Adobe Dreamweaver dsbnya)
+ Web Browser (Google Chrome, Internet Eplorer (IE), Mozilla Firefox, Safari dsbnya)

Setiap aplikasi di atas perlu dipasang (installation) satu-persatu dan dibuat tetapan (configuration) terlebih dahulu di dalam PC anda. Namun terdapat aplikasi yang telah mengabungkan beberapa aplikasi di atas dan memudahkan pengguna untuk membuat tetapan bagi setiap aplikasi tersebut. Sebagai contoh, Xampp, Easyphp, WAMP, PHPTriad dsbnya). Aplikasi ini telah mengumpulkan aplikasi PHP, Apache dan mySQL ke dalamnya. Jadi hanya perlu memasang aplikasi ini sahaja dan ketiga-tiga elemen penting untuk pembangunan website menggunakan PHP telah dipasang ke dalam PC anda. Kadang-kadang terdapat aplikasi/skrip tambahan turut di pasang di dalam aplikasi tersebut. Contohnya, PHPMyAdmin (GUI untuk menguruskan mysql), tomcat, filezilla, mercury dan sebagainya). Aplikasi ini adalah pilihan bagi anda yang ingin menggunakan aplikasi tersebut.

Namun perlu diingatkan aplikasi bundle ini hanya sesuai digunakan untuk pembangunan (development) sahaja dan bukan untuk produksi (production). Bagi tujuan produksi, adalah disarankan memasangan setiap aplikasi tersebut dibuat satu-persatu.


Pemasangan Xampp

Aplikasi yang akan digunakan untuk tutorial PakCu ini adalah:
+ Apache (web server)
+ PHP 5.4
+ mySQL (database)
+ Notepad++ (mungkin juga akan bertukar yg lain pada masa akan datang :p)
+ Google Chrome (i hate IE)

Anda boleh memuatturun aplikasi Xampp di url berikut – http://www.apachefriends.org/en/xampp.html. Ketika artikel ini ditulis, Xampp telah mengeluarkan versi 1.8.2 (bagi pengguna windows).

1 download

Apabila anda memuatturun versi apache/mysql/php yang hendak digunakan dalam proses pembangunan, sewajarnya hendaklah versi-versi tersebut sama seperti versi yang telah dipasang di dalam server produksi. Ini bagi mengelakkan masalah penggunaan fungsi di dalam aplikasi tersebut setelah ia dipindakan daripada server pembangunan ke server produksi.

Setelah fail tersebut berjaya dimuatturun, proses berikutnya adalah proses pemasangan aplikasi Xampp ke dalam PC anda. Klik 2 kali pada fail exe tersebut dan paparan berikut akan dipaparkan:

2 bahasa

Klik pada butang OK dan paparan berikut akan dipaparkan:

3 uac

Klik butang OK dan paparan berikut akan dipaparkan:

4 welcome

Klik butang Next untuk proses pemasangan selanjutnya dan paparan berikut akan dipaparkan:

5 component

Klik butang Next dan paparan berikut akan dipaparkan:

6 localtion

Anda boleh menukar lokasi pemasangan. Kemudian klik butang Install dan paparan progres pemasangan berikut akan dipaparkan:

7 install

Tunggu sehingga progres berakhir dan klik butang Next dan paparan berikut akan dipaparkan:

8 configure

Paparan ini akan tertutup secara automatik setelah proses configure selesai. Paparan berikut akan dipaparkan menandakan proses pemasangan Xampp selesai:

9 finish

 

 

phpMyAdmin Error: Connection for controluser as defined in your configuration failed.

  • Open phpMyAdmin in a browser and log in as root.
  • Create a database called phpmyadmin
  • Create a user called pma and set the “host” to the hostname or IP address of your web server (if the web server and MySQL are on the same box use localhost), make a note of the password, and grant the new user full control over the phpmyadmin database. It is recommended that this user does not have access to anything other than this database.
  • Go to the phpMyAdmin installation directory, where you should find a sub-directory calledexamples.
  • In examples you will find a file called create_tables.sql. Open it in a text editor.
  • In phpMyAdmin, select the phpmyadmin database and click on the “SQL” tab.
  • Copy/paste the entire text from create_tables.sql into the text box, and run the query.
  • Open the config.inc.php file in the phpMyAdmin install directory, and add the following lines (or change the existing settings if they are already there):
$cfg['Servers'][1]['pmadb'] = 'phpmyadmin';
$cfg['Servers'][1]['controluser'] = 'pma';
$cfg['Servers'][1]['controlpass'] = '<your password>';

$cfg['Servers'][1]['bookmarktable'] = 'pma_bookmark';
$cfg['Servers'][1]['relation'] = 'pma_relation';
$cfg['Servers'][1]['userconfig'] = 'pma_userconfig';
$cfg['Servers'][1]['table_info'] = 'pma_table_info';
$cfg['Servers'][1]['column_info'] = 'pma_column_info';
$cfg['Servers'][1]['history'] = 'pma_history';
$cfg['Servers'][1]['recent'] = 'pma_recent';
$cfg['Servers'][1]['table_uiprefs'] = 'pma_table_uiprefs';
$cfg['Servers'][1]['tracking'] = 'pma_tracking';
$cfg['Servers'][1]['table_coords'] = 'pma_table_coords';
$cfg['Servers'][1]['pdf_pages'] = 'pma_pdf_pages';
$cfg['Servers'][1]['designer_coords'] = 'pma_designer_coords';
  • Save and close the file.
  • Log out of phpMyAdmin
  • Log in again

Problem solved.

Sumber: Stackoverflow.Com

XML vs HTML

  1. XML is designed to carry the data while html is to display the data and focus on how the data looks.
  2. XML does not do anything but it is used to structure the data, store the data and transport the data while HTML is used to display the data only.
  3. XML is cross platform, hardware and software independent tool to carry data from one source to another destination.
  4. XML is self descriptive. The DTD or schema describes what and how to use tags and elements in an xml document.
  5. XML does not have predefined tags while HTML has. XML lets you invent your own tags while html gives you predefined tags and you have to use them only.
  6. XML is extensible as you can add your own tags to extend the xml data.
  7. XML is a complement to HTML not the replacement. Most likely use of xml is to transfer the data between incompatible systems as xml is cross platform. XML has now established a strong foundation in the world of web development.
  8. XML can separate the data from html.  While working on html, instead of storing data in html you can store the data in a separate xml file to make the html code cleaner and easier. Now you can concentrate on working in html rather than storing data. It also eliminates the need to change in html when xml data is changed.
  9. XML tags are case sensitive while html tags are not.
  10. Attribute values must always be quoted in xml while its not the case with html.
  11. XML elements must be properly nested while html is not so sensitive.

Perancangan 2013

Rasanya lama dah tak update blog ini dengan tutorial2 yang berkaitan dengan pengaturcaraan php & mysql. Alhamdulillah, sepanjang PakCu handling training utk Kursus PHP & mySQL (Asas & Pertengahan) serta Joomla, feeback yang diterima sangat menggalakan. Sampai hari ini masih ada peserta kursus yang call/email/msg bertanyakan persoalan berkaitan kandungan kursus yang diajar. Ini satu perkara yang positif antara pengajar dan pelajar. Oops! PakCu bukan nak mengajar.. cuma nak berkongsi ilmu sekerat-dua yang Allah berikan ini agar kita sama-sama dapat manfaat daripadanya.

Jadi untuk tahun 2013 ini, PakCu cadangan nak buat satu koleksi tutorial ilmu yang PakCu ada berkaitan dengan pengatucaraan dengan pengunjung semua. Sekurang-kurangnya ia boleh dijadikan rujukan kepada yang baru berjinak dengan dunia pengaturcaraan. Juga untuk peserta-peserta kursus refresh balik pembelajaran yang dikongsikan semasa dalam kelas/kursus yang telah dihadiri. Namun ingin PakCu menyatakan disini:

“Saya bukanlah pakar dalam bidang ini tapi saya amat minat dalam bidang ini dan tujuan saya menyediakan tutorial akan datang ini bukanlah untuk mengajar anda tentang cara terbaik (kerana ada yang lebih baik) tetapi sekadar berkongsi ilmu yang saya ada untuk manfaat kita semua”

Insyallah selain dari topik2 yang memang PakCu dah rancang nak buat, anda juga boleh usulkan topik2 yang berkaitan. Sekiranya topik tersebut dalam pengetahuan PakCu, insyallah PakCu akan buatkan tutorial.

PHP Meetup 2012

We are very excited to announce that, PHP Centre of Excellence and PHP.net.my community will team up again to organize PHP Malaysia Meetup 2012. The theme will be ‘API Mashup’. Expect Mashup experts, API enthusiasts and PHP lovers, exchanging ‘war’ of words, knowledge and what not in a very exciting and absolute fun environment. Mark your calendar and be there! Be yourself.. PHPeople PHPower!

Date : 3rd November 2012
Venue : Auditorium MIMOS Berhad, Technology Park Malaysia, Kuala Lumpur.
Registration : Free
Parking : Free
Wifi : Free
Knowledge : Free
Sponsors : AIST, Altfa Technologies, MIMOS, TM Applied Business
Supporters : Rynet Malaysia, Zend Technologies 

08.30 : Registration
09.00 : Opening remarks MIMOS Berhad
09.15 : Opening remarks php.net.my
09.30 : Coffee Break
10.00 : Enterprise PHP – Rama Yurindra (Rynet Malaysia Sdn Bhd)
10.45 : oAuth – Nurulazrad
11.30 : Twitter API – Muhammad Hamizi (TM Applied Bussiness)
12.15 : Facebook API – Mohd Izzairi (Xyiry Tech)
13.00 : Lunch
14.00 : Foursquare API – Ahmad Amran (AIST)
14.45 : Streaming Technology with AWS – Azril Nazli (CEA Resources)
15.30 : Paypal – Iszuddin Ismail (eSentral)
16.15 : MIMOS Mashup – Mary Ann Michael/Errazudin Ishak (MIMOS Berhad)
16.30 : Web API Best Practices – Prasant Kumar (Solution Engineer at Zend Technologies)
17.15 : Photoshoot session . End
Please register at : http://phpcoe.mimos.my/2012/10/php-malaysia-meetup-2012-api-mashup/