Guest User

Untitled

a guest
Jan 8th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. ?php
  2. function db_connect( $error=null, $configfile='database_config.php' )
  3. {
  4. require_once( $configfile );
  5. // $conn = pg_connect( "host=$server dbname=$database user=$user password=$password" );
  6. // $error= pg_last_error( $conn );
  7.  
  8. $conn = mysqli_connect( $server, $user, $password, $database );
  9. $error= mysqli_error( $conn );
  10. /* change character set to utf8 */
  11. mysqli_set_charset($conn, "utf8");
  12. return $conn;
  13. }
  14.  
  15. function db_query( $conn, $query, $error=null )
  16. {
  17. // $res=pg_query( $conn, $query );
  18. // $error=pg_last_error( $conn );
  19.  
  20. $res=mysqli_query( $conn, $query );
  21. $error=mysqli_error( $conn );
  22. return $res;
  23. }
  24.  
  25. function db_fetch( $result )
  26. {
  27. // return pg_fetch_assoc( $result );
  28.  
  29. return mysqli_fetch_assoc( $result );
  30. }
  31.  
  32. function db_genid( $link, $table, $idcol )
  33. {
  34. $res=db_query( $link, "select max($idcol) from $table" );
  35. $row=db_fetch( $res );
  36. if ( $res ) return $row[0]+1;
  37. return 1;
  38. }
  39.  
  40. function db_close( $conn )
  41. {
  42. // pg_close($conn);
  43.  
  44. mysqli_close($conn);
  45. }
  46. ?>
  47. <!DOCTYPE html>
  48. <html>
  49. <head>
  50. <title>Tworzenie tabeli</title>
  51. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  52. </head>
  53.  
  54. <body>
  55.  
  56. Dane tej tabeli:
  57. <table border="1">
  58. <?php
  59. $link=db_connect();
  60. $result=db_query( $link, "select * from osoba" );
  61. while ( $row=db_fetch( $result ) )
  62. {
  63. echo "<tr>";
  64. foreach ( $row as $col ) echo "<td>$col</td>";
  65. echo "</tr>";
  66. }
  67. db_close( $link );
  68. ?>
  69. </table>
  70. <hr><h2> Zrodlo pliku </h2>
  71. <?php
  72. show_source(__FILE__);
  73. ?>
  74. </body>
  75. </html>
Add Comment
Please, Sign In to add comment