Achmatim ~ Harapan Terindah

August 16, 2006

Bagaimana Mendapatkan Field Primary Key ?

Filed under: PHP

Seorang anggota milis phpug (http://groups.yahoo.com/group/phpug/) bertanya mengenai bagaimana mendapatkan nama id yang menjadi primary key dari suatu tabel MySQL.

fansul@xxx

ada nggak perintah mysql untuk mencari nama id key yang di
dalam table.
Bukan nomor urut id nya.
Soalnya kadang-2 orang bikin table untuk id kan bisa macam-2 kasih
nama.
Seperti ID, id_kary, id_sup dll
nah bagaimana saya bisa tahu kalau tabel ini nama id ini lho
terima kasih.

anghuda@xxx

bisa dong, ada caranya.

fansul@xxx

Caranya bagaimana pak

antonwhy@xxx

klo pake adodb tinggal gini aja = $fkey = $DB->MetaPrimaryKeys($table);

anghuda@xxx

besok deh, ada di rumah …

embartp@xxx

Kalo di mysql, desc, explain, show columns bisa ndak yak ?
Nah untuk php, mysql_fetch_fields ato mysql_field_type cukup ndak ?

anghuda@xxx

function getprimarykey($table){
$result = mysql_query(”SELECT * FROM $table LIMIT 1″);
while ($meta = mysql_fetch_field($result)) {
if ($meta->primary_key==1) {
$column = $meta->name;
break;
}
}
return $column;
}

solichin@xxx

Kalo seandainya primary key lebih dari 1 gimana ?

function getprimarykey($table){
$result = mysql_query(”SELECT * FROM $table LIMIT 1″);
$column = array();

while ($meta = mysql_fetch_field($result)) {
if ($meta->primary_key==1) {
$column[] = $meta->name;
}
}
return $column;
}

mungkin ada yang lebih efektif…?

embartp@xxx

Mas huda, kira2 perlu ndak ya tuh $column berupa array ?
Lagi ndak bisa nyobain codenya :(

anghuda@xxx

kira-kira begitulah, bisa pake array …
yg lebih efektif, selalu ada kemungkinan ,,,

August 15, 2006

What is PHP ?

Filed under: PHP

Googlism for: php

php is too easy
php is overtaking asp
php is an application
php is possible
php is developed and maintained by morons
php is for you
php is better then asp
php is to zend as modpython is to ???
php is a programming language for website applications
php is a standard
php is way better than asp
php is easy
php is working
php is installed correctly
php is cool (more…)

Get free blog up and running in minutes with Blogsome
Theme designed by Ian Main