Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //1. Create a database connection
- //$connection = mysql_connect("server", "user", "password");
- //$connection = mssql_connect("server", "user", "password");
- //handle is a reference to the connection
- $mysqli = mysqli_connect("localhost", "root", "psu", "ist402");
- if ($mysqli->connect_errno) {
- printf("Connect failed: %s\n", $mysqli->connect_error);
- exit();
- }
- ?>
- <html>
- <head>
- <title>Database</title>
- </head>
- <body>
- Five Steps for PHP Database Interaction<br />
- 1. Create the connection<br />
- 2. Select a database<br />
- 3. Preform database query<br />
- <?php
- //3 Perform database query
- $result = $mysqli->query("SELECT * from tblStudent");
- printf("Select returned %d rows.\n", $result->num_rows);
- $result->close();
- ?>
- 4. Use returned data (if any)<br />
- 5. Close the connection<br />
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement