Guest User

Untitled

a guest
Oct 27th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. <?php
  2.  
  3. $servername = "172.19.0.2";
  4. $username = "root";
  5. $password = "asdf";
  6. $dbname = "json_test";
  7.  
  8. // Create connection
  9. $conn = new mysqli($servername, $username, $password, $dbname);
  10.  
  11. // Check connection
  12. if ($conn->connect_error) {
  13. die("Connection failed: " . $conn->connect_error);
  14. }
  15.  
  16. $user_profile = array(
  17. 'firstname' => 'Mana',
  18. 'lastname' => 'Mungmana',
  19. 'ชื่อ' => 'มานะ',
  20. 'นามสกุล' => 'มุ่งมานะ'
  21. );
  22.  
  23. $user_profile = json_encode($user_profile, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
  24.  
  25. $sql = "INSERT INTO users (data)
  26. VALUES ('$user_profile')";
  27.  
  28. if ($conn->query($sql) === TRUE) {
  29. echo "New record created successfully";
  30. } else {
  31. echo "Error: " . $sql . "<br>" . $conn->error;
  32. }
  33.  
  34. $conn->close();
  35.  
  36. ?>
Add Comment
Please, Sign In to add comment