1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4. <head>
5. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
6. <title>Create the Database</title>
7. </head>
8. <body>
9. <?php // Script 12.3 - create_db.php
10. /* This script connects to the MySQL server. It also creates and selects the database. */
11.
12. // Attempt to connect to MySQL and print out messages:
13. if ($dbc = @mysql_connect('h41mysql35.secureserver.net', 'yrosenthal', 'Password.1')) {
14.
15. print '<p>Successfully connected to MySQL!</p>';
16.
17. // Try to create the database:
18. if (@mysql_query('CREATE DATABASE myblog')) {
19.
20. print '<p>The database has been created!</p>';
21.
22. } else { // Could not create it.
23. print '<p style="color: red;">Could not create the database because:<br />' . mysql_error() . '.</p>';
24. }
25.
26. // Try to select the database:
27. if (@mysql_select_db('myblog')) {
28. print '<p>The database has been selected.</p>';
29. } else {
30. print '<p style="color: red;">Could not select the database because:<br />' . mysql_error() . '.</p>';
31. }
32.
33. mysql_close(); // Close the connection.
34.
35. } else {
36.
37. print '<p style="color: red;">Could not connect to MySQL:<br />' . mysql_error() . '.</p>';
38.
39. }
40.
41. ?>
42. </body>
43. </html>