Guest User

Untitled

a guest
Jun 25th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.77 KB | None | 0 0
  1. <?php
  2. /*** mysql hostname ***/
  3. $hostname = 'localhost';
  4.  
  5. /*** mysql username ***/
  6. $username = 'root';
  7.  
  8. /*** mysql password ***/
  9. $password = '';
  10.  
  11. $dbname = 'test';
  12.  
  13. $link = connect($hostname, $username,$password);
  14.  
  15. function connect($hostname, $username, $password){
  16.     $link = @mysql_connect($hostname, $username, $password);
  17.     if (!$link)
  18.         die("Could not connect: ".mysql_error());
  19.     else{
  20.         $db = mysql_select_db('test');
  21.         if(!$db)
  22.             die("Could not select database: ".mysql_error());
  23.         else return $link;
  24.     }
  25. }
  26.  
  27.  
  28.  
  29. $result = mysql_query("SELECT * FROM stalkers",$link);
  30.  
  31. function getContent($result){
  32.     $final = array();
  33.     while($row = mysql_fetch_array($result)) {
  34.         $final[] = $row;
  35.     }
  36.     return $final;
  37. }
  38.  
  39. echo json_encode(getContent($result));
  40. ?>
Add Comment
Please, Sign In to add comment