PHP & MySQL for Dummies- P3
Số trang: 50
Loại file: pdf
Dung lượng: 0.00 B
Lượt xem: 7
Lượt tải: 0
Xem trước 5 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Tham khảo tài liệu php & mysql for dummies- p3, công nghệ thông tin, cơ sở dữ liệu phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
PHP & MySQL for Dummies- P3 Chapter 4: Building the Database 81 3 . If you’re starting the mysql client to access a database across the network, use the follow- ing parameter after the mysql command: -h host: host is the name of the machine where MySQL is located. For instance, if you’re in the directory where the mysql client is located, the command might look like this: mysql -h mysqlhost.mycompany.com -u root -p Press Enter after typing the command. 4 . Enter your password when prompted for it . The mysql client starts, and you see something similar to this: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 459 to server version: 5.0.15 Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer. mysql> 5 . Select the database that you want to use . At the mysql prompt, type the following: use databasename Use the name of the database that you want to query. 6 . At the mysql prompt, type your SQL query followed by a semicolon (;) and then press Enter . The mysql client continues to prompt for input and does not execute the query until you enter a semicolon. The response to the query is displayed onscreen. 7 . To leave the mysql client, type quit at the prompt and then press Enter . Using PHP scripts Because this book is about PHP and MySQL, the focus is on accessing MySQL databases from PHP scripts. PHP and MySQL work well together. PHP pro- vides built-in functions to interact with MySQL. You don’t need to know the details of interacting with the database because the functions handle all the details. You just need to know how to use the functions. PHP functions connect to the MySQL server, select the correct database, send a query, and receive any data that the query retrieves from the data- base. I explain using PHP functions to interact with your MySQL database in detail in Chapter 8.Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 82 Part II: MySQL Database Building a Database A database has two parts: a structure to hold the data and the data itself. In the following few sections, I explain how to create the database structure. First you create an empty database with no structure at all, and then you add tables to it. Rarely do you create your database from a PHP script. Generally, the database needs to exist before your Web application can perform its tasks — display data from the database, store data in the database, or both. Perhaps an appli- cation might require you to create a new table for each customer, such as create a new picture gallery or product information table for each individual. In this case, an application might need to create a new table while it is run- ning. But it’s unusual for an application to create a database or a table while running. Creating a new database You can create your new, empty database using phpMyAdmin. After you create a new database, you can add tables to it. Adding tables is explained later in this chapter. In this section, I explain how to create your new database on your local com- puter and on a Web hosting account. On your local computer To create a new empty database, take these steps: 1. Open the phpMyAdmin main page in a browser. The phpMyAdmin page opens. (Refer to Figure 4-1.) 2. Scroll down to the Create New Database heading. The heading is located in the left column of the main panel. 3. Type the name of the database you want to create into the blank field. 4. Click Create. When you create the new database, a new phpMyAdmin page is displayed, as s ...
Nội dung trích xuất từ tài liệu:
PHP & MySQL for Dummies- P3 Chapter 4: Building the Database 81 3 . If you’re starting the mysql client to access a database across the network, use the follow- ing parameter after the mysql command: -h host: host is the name of the machine where MySQL is located. For instance, if you’re in the directory where the mysql client is located, the command might look like this: mysql -h mysqlhost.mycompany.com -u root -p Press Enter after typing the command. 4 . Enter your password when prompted for it . The mysql client starts, and you see something similar to this: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 459 to server version: 5.0.15 Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer. mysql> 5 . Select the database that you want to use . At the mysql prompt, type the following: use databasename Use the name of the database that you want to query. 6 . At the mysql prompt, type your SQL query followed by a semicolon (;) and then press Enter . The mysql client continues to prompt for input and does not execute the query until you enter a semicolon. The response to the query is displayed onscreen. 7 . To leave the mysql client, type quit at the prompt and then press Enter . Using PHP scripts Because this book is about PHP and MySQL, the focus is on accessing MySQL databases from PHP scripts. PHP and MySQL work well together. PHP pro- vides built-in functions to interact with MySQL. You don’t need to know the details of interacting with the database because the functions handle all the details. You just need to know how to use the functions. PHP functions connect to the MySQL server, select the correct database, send a query, and receive any data that the query retrieves from the data- base. I explain using PHP functions to interact with your MySQL database in detail in Chapter 8.Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 82 Part II: MySQL Database Building a Database A database has two parts: a structure to hold the data and the data itself. In the following few sections, I explain how to create the database structure. First you create an empty database with no structure at all, and then you add tables to it. Rarely do you create your database from a PHP script. Generally, the database needs to exist before your Web application can perform its tasks — display data from the database, store data in the database, or both. Perhaps an appli- cation might require you to create a new table for each customer, such as create a new picture gallery or product information table for each individual. In this case, an application might need to create a new table while it is run- ning. But it’s unusual for an application to create a database or a table while running. Creating a new database You can create your new, empty database using phpMyAdmin. After you create a new database, you can add tables to it. Adding tables is explained later in this chapter. In this section, I explain how to create your new database on your local com- puter and on a Web hosting account. On your local computer To create a new empty database, take these steps: 1. Open the phpMyAdmin main page in a browser. The phpMyAdmin page opens. (Refer to Figure 4-1.) 2. Scroll down to the Create New Database heading. The heading is located in the left column of the main panel. 3. Type the name of the database you want to create into the blank field. 4. Click Create. When you create the new database, a new phpMyAdmin page is displayed, as s ...
Tìm kiếm theo từ khóa liên quan:
thủ thuật máy tính công nghệ thông tin tin học quản trị mạng computer networkTài liệu liên quan:
-
52 trang 434 1 0
-
24 trang 359 1 0
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 320 0 0 -
Làm việc với Read Only Domain Controllers
20 trang 311 0 0 -
74 trang 303 0 0
-
96 trang 299 0 0
-
Báo cáo thực tập thực tế: Nghiên cứu và xây dựng website bằng Wordpress
24 trang 291 0 0 -
Đồ án tốt nghiệp: Xây dựng ứng dụng di động android quản lý khách hàng cắt tóc
81 trang 286 0 0 -
EBay - Internet và câu chuyện thần kỳ: Phần 1
143 trang 277 0 0 -
Tài liệu hướng dẫn sử dụng thư điện tử tài nguyên và môi trường
72 trang 270 0 0