Read 204 times | Created 2013-01-20 04:45:46 | Updated 2013-01-20 04:45:46 | | |

 

<?php
/*********************************
FILENAME  : multicolumnindex.php
CREATE BY  : cahya dsn
PURPOSE   : check multicolumn index
CREATE DATE : 2013-01-20
**********************************
#table creation

USE `test`;

DROP TABLE IF EXISTS `t_buku`;
CREATE TABLE IF NOT EXISTS `t_buku` (
 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key untuk table t_buku',
 `judul` varchar(50) NOT NULL COMMENT 'judul',
 `pengarang` varchar(50) NOT NULL COMMENT 'pengarang',
 PRIMARY KEY(`id`) 
) ENGINE=MyISAM COMMENT='tabel untuk menyimpan data buku';

CREATE UNIQUE INDEX idx_judul_pengarang ON t_buku (`judul`, `pengarang`);

INSERT INTO `t_buku`(`id`,`judul`,`pengarang`)
VALUES (NULL,'judul1','pengarang1'),
(NULL,'judul2','pengarang1'),
(NULL,'judul3','pengarang1'),
(NULL,'judul1','pengarang2'),
(NULL,'judul2','pengarang3'),
(NULL,'judul3','pengarang3'),
(NULL,'judul4','pengarang2');

*/
$dbhost='localhost';
$dbuser='root';
$dbpass='';
$dbname='test';
$db = new mysqli($dbhost,$dbuser,$dbpass,$dbname);
$result=$db->query("INSERT INTO `t_buku`(`id`,`judul`,`pengarang`) VALUES (NULL,'judul1','pengarang1')");
echo 'Error number ['.$db->errno.'] => Error Message : '.$db->error;
$db->close();
?>