Advertisement
Guest User

Untitled

a guest
May 14th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.62 KB | None | 0 0
  1.  
  2. //connection parameters
  3. $hostname = 'localhost';
  4. $username = 'tbcj857';
  5. $mysql_pass = 'm2d59';
  6. $database = 'tbcj857';
  7.  
  8. //connect to mysql
  9.  
  10. $conx = mysql_connect ($hostname , $username , $mysql_pass)
  11. or die("Can't connect to MySQL" . mysql_error() );
  12.  
  13. //connect to specific database
  14. mysql_select_db ($database)
  15. or die("Can't select that database" . mysql_error() );
  16.  
  17. return $conx;
  18.  
  19. }
  20.  
  21. //Show a whole blog post on the page including the author, the blog title and body text
  22. //therefore i need to return data from
  23.  
  24. dbConnect();
  25.  
  26.  
  27.  
  28.  
  29. // include some php
  30. include 'php_include.php';
  31.  
  32.  
  33. echo '<div style="background:#ecc;border: 4px solid #dbb;">';
  34.  
  35. echo '<p>- Trying to echo the variable $a, defined in the php include: <br>';
  36. echo '<pre>$a is: ' . $a .'</pre></p>';
  37.  
  38.  
  39. echo '<p>- Calling the function hello(), defined in the php include: </p>';
  40.  
  41.  
  42.  
  43. hello('admin');
  44.  
  45.  
  46.  
  47.  
  48. // include some html
  49. include 'html_include.php';
  50.  
  51.  
  52. ?>
  53. <h3> this is in the body of the main file</h3>
  54.  
  55. <blockquote>
  56. <h4>From the manual re. include() :</h4>
  57. <p>"When a file is included, the code it contains inherits
  58.  
  59. <br/>the variable scope of the line on which the include occurs.
  60.  
  61. <br/><br/>Any <b>variables</b> available at that line in the calling file will be available <br/>
  62. within the called file, from that point forward.
  63.  
  64. <br/><br/>However, all <b>functions and classes</b> defined in the included file have the global scope."*** <br><br>[*** but only after the line on which they're included]</p>
  65.  
  66. <p>Try moving the php inculde around to see how it affects the scope of $a and hello()</p>
  67.  
  68. </blockquote>
  69.  
  70.  
  71. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement