| |
Download and install MySQL.
Open a command window and start MySQL.
cd \mysql\bin
mysqld
Create a database using the root account.
mysqladmin -u root create mydb
Create the following SQL which must be on
separate lines, making sure they lines don't wrap, and save it to
the MySQL bin directory, e.g.,
c:\mysql\bin\test.sql .
CREATE TABLE users (id tinyint(4) DEFAULT '0' NOT NULL AUTO_INCREMENT,
first varchar(20), last varchar(20), address varchar(255), company
varchar(50), PRIMARY KEY (id), UNIQUE id (id));
INSERT INTO users VALUES (1, 'Arnold','Fizbin','25 Wide St.','TinyCo');
INSERT INTO users VALUES (2, 'Fred', 'Fernakadan', '50 My Way', 'BigCo');
INSERT INTO users VALUES (3, 'Doris','Spam', '15 Top Rd', 'Zindi Corp');
If the lines wrap, make sure that each statement is on a new line.
Execute the create and inserts:
mysql -u root mydb <test.sql
Save the following page to
c:\program files\badblue\pe\mysql.php.
<html><body>
<?php
$db = mysql_connect("localhost", "root");
mysql_select_db("mydb", $db);
$result = mysql_query("SELECT * FROM users", $db);
printf("First Name: %s<br>\n", mysql_result($result, 0, "first"));
printf("Last Name: %s<br>\n", mysql_result($result, 0, "last"));
printf("Address: %s<br>\n", mysql_result($result, 0, "address"));
printf("Company: %s<br>\n", mysql_result($result, 0, "company"));
?>
</body></html>
Run the page in the browser to display the first record.
http://127.0.0.1/mysql.php
|