Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. <?php
  2. $servername = "222.222.222.222";
  3. $username = "dbuser";
  4. $password = "verycomplex password";
  5. $dbname = "myDb";
  6.  
  7. try {
  8. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  9. // set the PDO error mode to exception
  10. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  11.  
  12. $image = addslashes(file_get_contents('/home/pi/Desktop/image.jpg'));
  13. $imagename = addslashes("imagename");
  14.  
  15. $sql = "INSERT INTO info (image, imagename) VALUES ('$image', '$imagename')";
  16.  
  17. // use exec() because no results are returned
  18. $conn->exec($sql);
  19.  
  20. echo "New record created successfully";
  21. }
  22. catch(PDOException $e)
  23. {
  24. //echo $sql . "<br>" . $e->getMessage();
  25. echo "inside catch";
  26. }
  27.  
  28. $conn = null;
  29. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement