注意:
- 此教程需要访问 Oracle Cloud。要注册免费账户,请参阅开始使用 Oracle Cloud Infrastructure Free Tier 。
- 它使用 Oracle Cloud Infrastructure 身份证明、租户和区间示例值。完成实验室时,请将这些值替换为特定于您的云环境的值。
使用 OCI 数据库作为主后端来创建 Oracle Cloud Infrastructure Compute 实例 Web 服务器
简介
在本教程中,我们将创建一个由 Oracle Cloud Infrastructure (OCI) 计算实例组成的双层应用程序,该实例将充当 Web 服务器和 OCI 数据库服务 (MySQL)。我们创建了一个示例网站和数据库,此网站将从 OCI 数据库表中检索数据。
目标
-
我们将创建一个双层 Web 应用,使用面向公共互联网的 OCI 计算实例作为 PHP 和 NGINX Web 服务器的前端,使用带示例数据的面向专用 MySQL Database。安装 PHP MySQL 模块并创建包含示例数据的数据库,以便成功访问网站和示例数据。
-
任务 1:创建新的虚拟云网络 (virtual cloud network,VCN)。
-
任务 2:创建新公共子网和专用子网。
-
任务 3:创建新的 OCI 计算实例。
-
任务 4:创建新的 MySQL Database 引擎。
-
任务 5:使用示例数据创建新数据库。
-
任务 6:使用 PHP 安装和配置 NGINX Web 服务器。
-
任务 7:创建连接到数据库的网站,并在网页上显示记录。
-
任务 1:创建新的虚拟云网络 (VCN)
我们已创建 VCN,但如果您仍需要创建新的 VCN,请按照以下教程操作:在启用 IPv6 的情况下创建新 VCN 。
单击左上角的汉堡菜单。单击虚拟云网络以验证虚拟云网络是否存在。
对于本教程,我们已经有了 VCN。
任务 2:创建新的公共子网和专用子网
我们已经创建了一个公共和专用子网,但是如果您仍然需要创建新子网,请按照以下教程操作:在启用了 IPv6 的情况下创建新公共子网和在 VCN 中创建专用子网。
在此 VCN 中,我们有一个公共子网和专用子网可用。我们将 OCI 计算实例连接到公共子网,将 OCI 数据库连接到专用子网。
要查看可用的 OCI 计算实例,请单击左上角的汉堡菜单。
任务 3:创建新的 OCI 计算实例
我们已创建 OCI 计算实例,但如果您仍需要创建新的 OCI 计算实例,请按照以下教程操作:任务 3:在启用 IPv6 的情况下创建新实例。
单击实例可查看 OCI 计算实例。
面向公众的计算实例已启动并正在运行。
任务 4:创建新的 MySQL Database 引擎
-
单击左上角的汉堡菜单。
- 单击数据库。
- 单击 MySQL HeatWave 。
-
单击创建数据库系统。
-
在创建数据库系统中,输入以下信息。
- 选择 Development or Testing 。
- 输入名称。
- 向下滚动。
-
在创建管理员身份证明部分中,输入以下信息。
- 输入用户名。
- 输入口令。
- 输入确认口令。
- 选择 Standalone 。
- 向下滚动。
- 为数据库选择 VCN。
- 选择要连接数据库的专用子网。
- 向下滚动。
-
向下滚动。
-
单击创建以创建数据库。
-
检查数据库状态是否为 CREATING 。
查看数据库状态是否为更新。
- 查看数据库状态是否为 ACTIVE 。
- 单击连接选项卡。
查看以后将用于配置和访问 MySQL Database 的专用 IP 地址 10.0.2.247
。
任务 5:使用示例数据创建新数据库(包含 2 个记录的 1 个表)
-
要访问和配置 MySQL Database,需要安装 MySQL Shell。运行以下命令进行安装。
[opc@ih-webserver-01 ~]$ sudo yum install mysql-shell
-
要访问 MySQL Database,请使用以下命令。
注:我们无法连接到 MySQL Database,原因是我们不允许默认安全列表中的数据库端口。
-
单击 OCI 控制台中的汉堡包菜单。
- 单击网络
- 单击虚拟云网络。
-
单击 VCN。
-
向下滚动。
-
单击安全列表和默认安全列表。
-
单击添加入站规则。
-
在添加入站规则中,输入以下信息。
- 源类型:选择 CIDR 。
- 源 CIDR:要允许来自所有源的流量,请输入
0.0.0.0/0
。 - IP 协议:选择 TCP 。
- 目标端口范围:输入 33060 。
- 单击添加入站规则。
-
单击添加入站规则。
-
在添加入站规则中,输入以下信息。
- 源类型:选择 CIDR 。
- 源 CIDR:要允许来自所有源的流量,请输入
0.0.0.0/0
。 - IP 协议:选择 TCP 。
- 目标端口范围:输入 33060 。
- 单击添加入站规则。
- 向下滚动。
- 检查是否配置了 TCP 端口
33060
和3306
的规则。
-
将入站规则添加到默认安全列表后,我们可以使用带以下命令的 MySQL Shell 访问 OCI 数据库。
[opc@ih-webserver-01 ~]$ mysqlsh admin@10.0.2.247 Please provide the password for 'admin@10.0.2.247': **************** Save password for 'admin@10.0.2.247'? [Y]es/[N]o/Ne[v]er (default No): Y MySQL Shell 8.0.35 Copyright (c) 2016, 2023, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type '\help' or '\?' for help; '\quit' to exit. Creating a session to 'admin@10.0.2.247' Fetching schema names for auto-completion... Press ^C to stop. Your MySQL connection id is 50 (X protocol) Server version: 8.0.36-u1-cloud MySQL Enterprise - Cloud No default schema selected; type \use <schema> to set one. MySQL 10.0.2.247:33060+ ssl JS >
我们现在能够成功访问 OCI 数据库。
-
使用 MySQL Shell 访问 OCI 数据库后,以下命令将通过启用自动保存、命令历史记录和模式来简化使用。
MySQL 10.0.2.247:33060+ ssl JS > shell.options.setPersist('history.autoSave', 1) MySQL 10.0.2.247:33060+ ssl JS > shell.options.setPersist('history.maxSize', 5000) MySQL 10.0.2.247:33060+ ssl JS > shell.options.setPersist('defaultMode', 'sql')
-
要显示所有现有数据库,请使用以下命令。
MySQL 10.0.2.247:33060+ ssl SQL > SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | mysql_audit | | performance_schema | | sys | +--------------------+ 5 rows in set (0.0015 sec) MySQL 10.0.2.247:33060+ ssl SQL >
-
要创建新数据库,请使用以下命令。
MySQL 10.0.2.247:33060+ ssl SQL > CREATE DATABASE F1; Query OK, 1 row affected (0.0066 sec)
-
要验证数据库是否已创建,请使用以下命令。
MySQL 10.0.2.247:33060+ ssl SQL > SHOW DATABASES; +--------------------+ | Database | +--------------------+ | F1 | | information_schema | | mysql | | mysql_audit | | performance_schema | | sys | +--------------------+ 6 rows in set (0.0010 sec) MySQL 10.0.2.247:33060+ ssl SQL >
-
要使用新数据库(创建表和记录),请使用以下命令。
MySQL 10.0.2.247:33060+ ssl SQL > USE F1 Default schema set to `F1`. Fetching global names, object names from `F1` for auto-completion... Press ^C to stop. MySQL 10.0.2.247:33060+ ssl F1 SQL >
-
要显示数据库中的所有现有表,请使用以下命令。
MySQL 10.0.2.247:33060+ ssl F1 SQL > SHOW TABLES; Empty set (0.0013 sec) MySQL 10.0.2.247:33060+ ssl F1 SQL >
-
要使用某些列创建新表,请使用以下命令。
MySQL 10.0.2.247:33060+ ssl F1 SQL > CREATE TABLE drivers(First_Name VARCHAR(50) NOT NULL,Last_Name VARCHAR(50) NOT NULL,PRIMARY KEY(Last_Name)); Query OK, 0 rows affected (0.0207 sec) MySQL 10.0.2.247:33060+ ssl F1 SQL >
-
要验证数据库中的所有表,请使用以下命令。
MySQL 10.0.2.247:33060+ ssl F1 SQL > DESCRIBE drivers; +------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+-------------+------+-----+---------+-------+ | First_Name | varchar(50) | NO | | NULL | | | Last_Name | varchar(50) | NO | PRI | NULL | | +------------+-------------+------+-----+---------+-------+ 2 rows in set (0.0022 sec) MySQL 10.0.2.247:33060+ ssl F1 SQL >
-
要在表中创建新记录,请使用以下命令。
MySQL 10.0.2.247:33060+ ssl F1 SQL > INSERT INTO drivers VALUE ("Max", "Verstappen"); Query OK, 1 row affected (0.0048 sec) MySQL 10.0.2.247:33060+ ssl F1 SQL > INSERT INTO drivers VALUE ("Sergio", "Pérez"); Query OK, 1 row affected (0.0024 sec) MySQL 10.0.2.247:33060+ ssl F1 SQL >
-
要验证是否在表中创建了两条新记录,请使用以下命令。
MySQL 10.0.2.247:33060+ ssl F1 SQL > SELECT * FROM drivers; +------------+------------+ | First_Name | Last_Name | +------------+------------+ | Sergio | Pérez | | Max | Verstappen | +------------+------------+ 2 rows in set (0.0006 sec) MySQL 10.0.2.247:33060+ ssl F1 SQL >
-
要创建新用户并为新数据库提供适当的权限,请使用以下命令。
MySQL 10.0.2.247:33060+ ssl SQL > CREATE USER 'iwan'@'%' IDENTIFIED WITH mysql_native_password BY 'XXX'; Query OK, 0 rows affected (0.0035 sec) MySQL 10.0.2.247:33060+ ssl SQL > GRANT ALL ON F1.* TO 'iwan'@'%'; Query OK, 0 rows affected (0.0037 sec) MySQL 10.0.2.247:33060+ ssl SQL >
-
要验证新用户是否具有对数据库的正确权限,请使用以下命令。
MySQL 10.0.2.247:33060+ ssl SQL > SHOW GRANTS FOR 'iwan'; +----------------------------------------------+ | Grants for iwan@% | +----------------------------------------------+ | GRANT USAGE ON *.* TO `iwan`@`%` | | GRANT ALL PRIVILEGES ON `F1`.* TO `iwan`@`%` | +----------------------------------------------+ 2 rows in set (0.0006 sec) MySQL 10.0.2.247:33060+ ssl SQL >
-
要关闭 MySQL Shell,请运行
\q
命令。MySQL 10.0.2.247:33060+ ssl F1 SQL > \q Bye! [opc@ih-webserver-01 ~]$
现在,我们有一个示例数据库,其中包含使用 OCI Database MySQL 服务在 OCI 中运行的一些示例表和示例数据。下一个任务是使用 PHP 网站检索此数据。
任务 6:使用 PHP 安装和配置 NGINX Web 服务器
我们已经创建了包含 NGNIX 和 PHP 的计算实例,但是如果您仍然需要使用 NGNIX 和 PHP 创建新实例,请按照教程操作:任务 6:在实例上安装 Web 服务器。
在之前的带有 PHP 设置的 NGINX 中,我们没有安装任何 PHP MySQL 模块。在 PHP 信息页面上快速检查将确认这一点。
-
使用以下命令安装 PHP MySQL 模块,以便 NGINX 和 PHP 可以与 MySQL 一起使用。
[opc@ih-webserver-01 html]$ sudo dnf install php php-common php-mysqlnd php-pecl-zip php-gd php-mbstring php-xml php-soap Last metadata expiration check: 2:28:09 ago on Fri 16 Feb 2024 08:40:17 AM GMT. Package php-7.2.24-1.module+el8.2.0+5510+6771133c.x86_64 is already installed. Package php-common-7.2.24-1.module+el8.2.0+5510+6771133c.x86_64 is already installed. Dependencies resolved. ====================================================================================================================== Package Architecture Version Repository Size ====================================================================================================================== Installing: php-gd x86_64 7.2.24-1.module+el8.2.0+5510+6771133c ol8_appstream 84 k php-mbstring x86_64 7.2.24-1.module+el8.2.0+5510+6771133c ol8_appstream 581 k php-mysqlnd x86_64 7.2.24-1.module+el8.2.0+5510+6771133c ol8_appstream 191 k php-pecl-zip x86_64 1.15.3-1.module+el8+5148+a558e3ee ol8_appstream 51 k php-soap x86_64 7.2.24-1.module+el8.2.0+5510+6771133c ol8_appstream 177 k php-xml x86_64 7.2.24-1.module+el8.2.0+5510+6771133c ol8_appstream 189 k Installing dependencies: gd x86_64 2.2.5-7.el8 ol8_appstream 144 k jbigkit-libs x86_64 2.1-14.el8 ol8_appstream 55 k libXpm x86_64 3.5.12-9.el8_7 ol8_appstream 58 k libjpeg-turbo x86_64 1.5.3-12.el8 ol8_appstream 157 k libtiff x86_64 4.0.9-29.el8_8 ol8_appstream 189 k libwebp x86_64 1.0.0-9.el8_9.1 ol8_appstream 273 k libzip x86_64 1.5.1-2.module+el8.2.0+5510+6771133c ol8_appstream 63 k php-pdo x86_64 7.2.24-1.module+el8.2.0+5510+6771133c ol8_appstream 123 k Transaction Summary ====================================================================================================================== Install 14 Packages Total download size: 2.3 M Installed size: 6.1 M Is this ok [y/N]: y Downloading Packages: (1/14): libXpm-3.5.12-9.el8_7.x86_64.rpm 253 kB/s | 58 kB 00:00 (2/14): jbigkit-libs-2.1-14.el8.x86_64.rpm 232 kB/s | 55 kB 00:00 (3/14): libjpeg-turbo-1.5.3-12.el8.x86_64.rpm 13 MB/s | 157 kB 00:00 (4/14): libtiff-4.0.9-29.el8_8.x86_64.rpm 19 MB/s | 189 kB 00:00 (5/14): gd-2.2.5-7.el8.x86_64.rpm 571 kB/s | 144 kB 00:00 (6/14): libwebp-1.0.0-9.el8_9.1.x86_64.rpm 22 MB/s | 273 kB 00:00 (7/14): libzip-1.5.1-2.module+el8.2.0+5510+6771133c.x86_64.rpm 846 kB/s | 63 kB 00:00 (8/14): php-gd-7.2.24-1.module+el8.2.0+5510+6771133c.x86_64.rpm 963 kB/s | 84 kB 00:00 (9/14): php-mbstring-7.2.24-1.module+el8.2.0+5510+6771133c.x86_64.rpm 3.9 MB/s | 581 kB 00:00 (10/14): php-pdo-7.2.24-1.module+el8.2.0+5510+6771133c.x86_64.rpm 1.9 MB/s | 123 kB 00:00 (11/14): php-mysqlnd-7.2.24-1.module+el8.2.0+5510+6771133c.x86_64.rpm 1.2 MB/s | 191 kB 00:00 (12/14): php-soap-7.2.24-1.module+el8.2.0+5510+6771133c.x86_64.rpm 1.1 MB/s | 177 kB 00:00 (13/14): php-pecl-zip-1.15.3-1.module+el8+5148+a558e3ee.x86_64.rpm 308 kB/s | 51 kB 00:00 (14/14): php-xml-7.2.24-1.module+el8.2.0+5510+6771133c.x86_64.rpm 1.8 MB/s | 189 kB 00:00 ---------------------------------------------------------------------------------------------------------------------- Total 3.9 MB/s | 2.3 MB 00:00 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : libjpeg-turbo-1.5.3-12.el8.x86_64 1/14 Installing : libXpm-3.5.12-9.el8_7.x86_64 2/14 Installing : php-pdo-7.2.24-1.module+el8.2.0+5510+6771133c.x86_64 3/14 Installing : libzip-1.5.1-2.module+el8.2.0+5510+6771133c.x86_64 4/14 Installing : libwebp-1.0.0-9.el8_9.1.x86_64 5/14 Installing : jbigkit-libs-2.1-14.el8.x86_64 6/14 Running scriptlet: jbigkit-libs-2.1-14.el8.x86_64 6/14 Installing : libtiff-4.0.9-29.el8_8.x86_64 7/14 Installing : gd-2.2.5-7.el8.x86_64 8/14 Running scriptlet: gd-2.2.5-7.el8.x86_64 8/14 Installing : php-gd-7.2.24-1.module+el8.2.0+5510+6771133c.x86_64 9/14 Installing : php-pecl-zip-1.15.3-1.module+el8+5148+a558e3ee.x86_64 10/14 Installing : php-mysqlnd-7.2.24-1.module+el8.2.0+5510+6771133c.x86_64 11/14 Installing : php-xml-7.2.24-1.module+el8.2.0+5510+6771133c.x86_64 12/14 Installing : php-soap-7.2.24-1.module+el8.2.0+5510+6771133c.x86_64 13/14 Installing : php-mbstring-7.2.24-1.module+el8.2.0+5510+6771133c.x86_64 14/14 Running scriptlet: php-mbstring-7.2.24-1.module+el8.2.0+5510+6771133c.x86_64 14/14 Verifying : gd-2.2.5-7.el8.x86_64 1/14 Verifying : jbigkit-libs-2.1-14.el8.x86_64 2/14 Verifying : libXpm-3.5.12-9.el8_7.x86_64 3/14 Verifying : libjpeg-turbo-1.5.3-12.el8.x86_64 4/14 Verifying : libtiff-4.0.9-29.el8_8.x86_64 5/14 Verifying : libwebp-1.0.0-9.el8_9.1.x86_64 6/14 Verifying : libzip-1.5.1-2.module+el8.2.0+5510+6771133c.x86_64 7/14 Verifying : php-gd-7.2.24-1.module+el8.2.0+5510+6771133c.x86_64 8/14 Verifying : php-mbstring-7.2.24-1.module+el8.2.0+5510+6771133c.x86_64 9/14 Verifying : php-mysqlnd-7.2.24-1.module+el8.2.0+5510+6771133c.x86_64 10/14 Verifying : php-pdo-7.2.24-1.module+el8.2.0+5510+6771133c.x86_64 11/14 Verifying : php-pecl-zip-1.15.3-1.module+el8+5148+a558e3ee.x86_64 12/14 Verifying : php-soap-7.2.24-1.module+el8.2.0+5510+6771133c.x86_64 13/14 Verifying : php-xml-7.2.24-1.module+el8.2.0+5510+6771133c.x86_64 14/14 Installed: gd-2.2.5-7.el8.x86_64 jbigkit-libs-2.1-14.el8.x86_64 libXpm-3.5.12-9.el8_7.x86_64 libjpeg-turbo-1.5.3-12.el8.x86_64 libtiff-4.0.9-29.el8_8.x86_64 libwebp-1.0.0-9.el8_9.1.x86_64 libzip-1.5.1-2.module+el8.2.0+5510+6771133c.x86_64 php-gd-7.2.24-1.module+el8.2.0+5510+6771133c.x86_64 php-mbstring-7.2.24-1.module+el8.2.0+5510+6771133c.x86_64 php-mysqlnd-7.2.24-1.module+el8.2.0+5510+6771133c.x86_64 php-pdo-7.2.24-1.module+el8.2.0+5510+6771133c.x86_64 php-pecl-zip-1.15.3-1.module+el8+5148+a558e3ee.x86_64 php-soap-7.2.24-1.module+el8.2.0+5510+6771133c.x86_64 php-xml-7.2.24-1.module+el8.2.0+5510+6771133c.x86_64 Complete! [opc@ih-webserver-01 html]$
-
运行以下命令以编辑
php.ini
文件。[opc@ih-webserver-01 testocidb]$ sudo nano /etc/php.ini
-
确保此行未注释,以便可以装入
mysqli.so
模块。extension=/usr/lib64/php/modules/mysqli.so
-
使用以下命令重新启动 NGINX 和 PHP 服务。
[opc@ih-webserver-01 testocidb]$ sudo systemctl start php-fpm [opc@ih-webserver-01 testocidb]$ sudo systemctl restart nginx
-
现在,PHP 信息页面确认已安装 PHP MySQL 模块。
-
对于本教程,我们使用的是 Oracle Linux 8,它基于 SE Linux,我们需要运行以下命令来允许 Web 服务器 (NGINX) 连接和访问 MySQL Database。
[opc@ih-webserver-01 testocidb]$ sudo setsebool -P httpd_can_network_connect_db=1
注:请勿在 PHP 网站上运行上述命令,这可能会给您带来错误:无法连接:无法连接到 MySQL 服务器。
任务 7:创建连接到数据库的网站,并在网页上显示记录
-
要将 Web 服务器上的目录更改为 Web 服务器文件的默认路径,请使用以下命令。
[opc@ih-webserver-01 ~]$ cd /usr/share/nginx/html/ [opc@ih-webserver-01 html]$ ls -l total 60 -rw-r--r--. 1 root root 168 Feb 8 07:47 404.php -rw-r--r--. 1 root root 497 Oct 24 16:50 50x.html -rw-r--r--. 1 root root 7 Feb 8 09:54 Color -rw-r--r--. 1 root root 9731 Feb 8 10:18 Iwan-hoogendoorn.logo.png -rw-r--r--. 1 root root 15406 Feb 8 10:07 favicon.ico drwxr-xr-x. 2 root root 101 Feb 8 09:59 files -rw-r--r--. 1 root root 8 Feb 8 09:52 health.html -rw-r--r--. 1 root root 622 Feb 7 18:13 index.html.original -rw-r--r--. 1 root root 6504 Feb 8 10:23 index.php -rw-r--r--. 1 root root 18 Feb 7 19:28 info.php [opc@ih-webserver-01 html]$
-
要为新的测试网页创建新目录,请使用以下命令。
[opc@ih-webserver-01 html]$ sudo mkdir testocidb [opc@ih-webserver-01 html]$ ls -l total 60 -rw-r--r--. 1 root root 168 Feb 8 07:47 404.php -rw-r--r--. 1 root root 497 Oct 24 16:50 50x.html -rw-r--r--. 1 root root 7 Feb 8 09:54 Color -rw-r--r--. 1 root root 9731 Feb 8 10:18 Iwan-hoogendoorn.logo.png -rw-r--r--. 1 root root 15406 Feb 8 10:07 favicon.ico drwxr-xr-x. 2 root root 101 Feb 8 09:59 files -rw-r--r--. 1 root root 8 Feb 8 09:52 health.html -rw-r--r--. 1 root root 622 Feb 7 18:13 index.html.original -rw-r--r--. 1 root root 6504 Feb 8 10:23 index.php -rw-r--r--. 1 root root 18 Feb 7 19:28 info.php drwxr-xr-x. 2 root root 6 Feb 16 09:47 testocidb [opc@ih-webserver-01 html]$
-
将目录更改为新创建的目录并创建新的
index.php
文件。此文件将是用于连接到 OCI 数据库的测试网站,从数据库中提取数据并将其显示在网站上。
[opc@ih-webserver-01 html]$ cd testocidb/ [opc@ih-webserver-01 testocidb]$ sudo nano index.php
-
测试网站的 HTML 和 PHP 代码可以在下面找到。如果您正在使用此网页,请确保更改数据库 IP、名称、用户名和密码详细信息。
根据您的数据库表和数据结构,您可以更改代码以反映您的示例。
[opc@ih-webserver-01 testocidb]$ sudo more index.php <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Database Records</title> <style> table{ width: 70%; margin: auto; font-family: Arial, Helvetica, sans-serif; } table, tr, th, td{ border: 1px solid #d4d4d4; border-collapse: collapse; padding: 12px; } th, td{ text-align: left; vertical-align: top; } tr:nth-child(even){ background-color: #e7e9eb; } </style> <body> <?php //storing database details in variables. $hostname = "10.0.2.247"; $username = "iwan"; $password = "XXX"; $dbname = "F1"; //creating connection to database $con = mysqli_connect($hostname, $username, $password, $dbname); //checking if connection is working or not if(!$con) { die("<p><center>Connection failed! <br></center></p>" . mysqli_connect_error()); } else { echo "<p><center>Successfully Connected! <br></center></p>"; } //Output Form Entries from the Database $sql = "SELECT First_Name, Last_Name FROM drivers"; //fire query $result = mysqli_query($con, $sql); if(mysqli_num_rows($result) > 0) { echo '<table> <tr> <th> First Name </th> <th> Last Name </th> </tr>'; while($row = mysqli_fetch_assoc($result)){ // to output mysql data in HTML table format echo '<tr > <td>' . $row["First_Name"] . '</td> <td>' . $row["Last_Name"] . '</td>'; } echo '</table>'; } else { echo "0 results"; } // closing connection mysqli_close($con); ?> </body> </html> [opc@ih-webserver-01 testocidb]$
当我们连接到网站 /testocidb/index.php
时,我们能够成功访问该网站,最重要的是,我们将看到数据库中存储的数据。
确认
- 作者 - Iwan Hoogendoorn(OCI 网络专家)
更多学习资源
浏览 docs.oracle.com/learn 上的其他实验室,或者通过 Oracle Learning YouTube 频道访问更多免费学习内容。此外,请访问 education.oracle.com/learning-explorer 以成为 Oracle Learning Explorer。
有关产品文档,请访问 Oracle 帮助中心。
Create an Oracle Cloud Infrastructure Compute Instance Webserver using an OCI Database as the main Backend
F94443-01
March 2024
Copyright © 2024, Oracle and/or its affiliates.