Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ?php
- function db_connect( $error=null, $configfile='database_config.php' )
- {
- require_once( $configfile );
- // $conn = pg_connect( "host=$server dbname=$database user=$user password=$password" );
- // $error= pg_last_error( $conn );
- $conn = mysqli_connect( $server, $user, $password, $database );
- $error= mysqli_error( $conn );
- /* change character set to utf8 */
- mysqli_set_charset($conn, "utf8");
- return $conn;
- }
- function db_query( $conn, $query, $error=null )
- {
- // $res=pg_query( $conn, $query );
- // $error=pg_last_error( $conn );
- $res=mysqli_query( $conn, $query );
- $error=mysqli_error( $conn );
- return $res;
- }
- function db_fetch( $result )
- {
- // return pg_fetch_assoc( $result );
- return mysqli_fetch_assoc( $result );
- }
- function db_genid( $link, $table, $idcol )
- {
- $res=db_query( $link, "select max($idcol) from $table" );
- $row=db_fetch( $res );
- if ( $res ) return $row[0]+1;
- return 1;
- }
- function db_close( $conn )
- {
- // pg_close($conn);
- mysqli_close($conn);
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Tworzenie tabeli</title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- </head>
- <body>
- Dane tej tabeli:
- <table border="1">
- <?php
- $link=db_connect();
- $result=db_query( $link, "select * from osoba" );
- while ( $row=db_fetch( $result ) )
- {
- echo "<tr>";
- foreach ( $row as $col ) echo "<td>$col</td>";
- echo "</tr>";
- }
- db_close( $link );
- ?>
- </table>
- <hr><h2> Zrodlo pliku </h2>
- <?php
- show_source(__FILE__);
- ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment