Advertisement
GWibisono

insert sederhana

Apr 12th, 2014
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.70 KB | None | 0 0
  1. <?php
  2. /*
  3. table ada dibawah tolong dibuat dahulu
  4. */
  5. //======KONEKSI... pake mysqli (tolong ganti isinya sesuai kebutuhan)
  6. $mysqli = new mysqli("localhost", "root", "", "test");
  7.  
  8. /* check connection */
  9. if (mysqli_connect_errno()) {
  10.     printf("Connect failed: %s\n", mysqli_connect_error());
  11.     exit();
  12. }
  13.  
  14. printf("Host information: %s\n", $mysqli->host_info);
  15.  
  16. $sql="insert into test(code) values ('".time()."')";
  17. $r=$mysqli->query($sql);
  18. if(!$r)
  19. {
  20.     echo "error :".$mysqli->error;
  21. }else{
  22.     echo "OK";
  23. }
  24. /* close connection */
  25. $mysqli->close();
  26.  
  27.  
  28. /*
  29. CREATE TABLE IF NOT EXISTS `test` (
  30.   `code` int(11) NOT NULL,
  31.   `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
  32. ) ENGINE=MyISAM
  33. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement