Guest User

Untitled

a guest
Jan 23rd, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. $servername = "localhost";
  2. $username = "root";
  3. $password = "";
  4. $dbname = "tesddddt";
  5.  
  6. $conn = mysqli_connect($servername, $username, $password, $dbname);
  7. mysqli_set_charset($conn,"utf8");
  8.  
  9. if (!$conn) {
  10. die("Connection failed: " . mysqli_connect_error());
  11. }
  12. $sql = "SELECT * FROM customer";
  13. $result = mysqli_query($conn, $sql);
  14.  
  15. if (mysqli_num_rows($result) > 0) {
  16. // output data of each row
  17. while($row = mysqli_fetch_assoc($result)) {
  18. echo "id: " . $row["uid"]. " - Name: " . $row["username"]. " " . $row["email"]. "<br>";
  19. }
  20. } else {
  21. echo "0 results";
  22. }
  23.  
  24. public function __construct(){
  25. try {
  26.  
  27. $conn = new PDO("mysql:host=$this->db_host;dbname=$this->db_name", $this->db_user_name, $this->db_pass);
  28. mysqli_set_charset($conn,"utf8"); // <- added here
  29. $this->conn=$conn;
  30. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  31.  
  32. }
  33. catch(PDOException $e)
  34. {
  35. echo "Connection failed: " . $e->getMessage();
  36. }
  37. }
  38.  
  39. Warning: mysqli_set_charset() expects parameter 1 to be mysqli, object given in...
  40.  
  41. $conn = new PDO("mysql:host=yourhost;dbname=yourdbname;charset=utf8");
  42.  
  43. header("Content-Type: text/html; charset=utf-8");
  44. //header("Content-Type: text/html; charset=utf-8_general_ci");
  45. //error_reporting(E_ALL);
  46. ini_set('display_errors', true);
  47. set_time_limit(480);
  48. define("DSN", "mysql:host=localhost;dbname=biblewheel");
Add Comment
Please, Sign In to add comment