Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Table in DB:
- create table a_first (request varchar(30), answer varchar(30)) ;
- insert into a_first values ('qwe','asd') ;
- insert into a_first values ('rty','fgh') ;
- //Contains of /usr/share/php/db.php
- $servername="ip_address";
- $username="mysql_user";
- $password="mysql_pass";
- $dbname="dbname" ;
- //Contains of /usr/share/nginx/html/test.php
- <?php
- echo "<html><header></header><body>";
- require_once 'db.php';
- echo "test page" ;
- echo "<br>" ;
- $conn = mysql_connect($servername, $username, $password);
- if (!$conn) {
- die('cani't connect: ' . mysql_error());
- }
- $db_selected = mysql_select_db($dbname, $conn);
- if (!$db_selected) {
- die ('can't select DB: ' . mysql_error());
- }
- $sql = "select * from a_first; " ;
- $result = mysql_query($sql);
- if (!$result) {
- die('SQL error: ' . mysql_error());
- }
- while ($row = mysql_fetch_assoc($result)) {
- echo $row['request']." - ".$row['answer']." n";
- echo "<br>n" ;
- }
- mysql_free_result($result);
- echo "</body></html>";
- ?>
Add Comment
Please, Sign In to add comment