Advertisement
Guest User

Untitled

a guest
Sep 10th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. <?php
  2. /*********************************
  3. FILENAME : multicolumnindex.php
  4. CREATE BY : cahya dsn
  5. PURPOSE : check multicolumn index
  6. CREATE DATE : 2013-01-20
  7. **********************************
  8. #table creation
  9.  
  10. USE `test`;
  11.  
  12. DROP TABLE IF EXISTS `t_buku`;
  13. CREATE TABLE IF NOT EXISTS `t_buku` (
  14. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key untuk table t_buku',
  15. `judul` varchar(50) NOT NULL COMMENT 'judul',
  16. `pengarang` varchar(50) NOT NULL COMMENT 'pengarang',
  17. PRIMARY KEY(`id`)
  18. ) ENGINE=MyISAM COMMENT='tabel untuk menyimpan data buku';
  19.  
  20. CREATE UNIQUE INDEX idx_judul_pengarang ON t_buku (`judul`, `pengarang`);
  21.  
  22. INSERT INTO `t_buku`(`id`,`judul`,`pengarang`)
  23. VALUES (NULL,'judul1','pengarang1'),
  24. (NULL,'judul2','pengarang1'),
  25. (NULL,'judul3','pengarang1'),
  26. (NULL,'judul1','pengarang2'),
  27. (NULL,'judul2','pengarang3'),
  28. (NULL,'judul3','pengarang3'),
  29. (NULL,'judul4','pengarang2');
  30.  
  31. */
  32. $dbhost='localhost';
  33. $dbuser='root';
  34. $dbpass='';
  35. $dbname='test';
  36. $db = new mysqli($dbhost,$dbuser,$dbpass,$dbname);
  37. $result=$db->query("INSERT INTO `t_buku`(`id`,`judul`,`pengarang`) VALUES (NULL,'judul1','pengarang1')");
  38. echo 'Error number ['.$db->errno.'] => Error Message : '.$db->error;
  39. $db->close();
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement