OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Database

SQL - V4.3.1

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogWhite PaperLive DemosTraining & CertificationTicket
    Company
    About OceanBaseTrust CenterLegalPartnerContact Us
    Follow Us

    © OceanBase 2026. All rights reserved

    Cloud Service AgreementPrivacy PolicySecurity
    Contact Us
    Document Feedback
    1. Documentation Center
    2. OceanBase Database
    3. SQL
    4. V4.3.1
    iconOceanBase Database
    SQL - V 4.3.1
    Databases
    • OceanBase Database
    • OceanBase Cloud
    • OceanBase Tugraph
    • Interactive Tutorials
    • OceanBase Best Practices
    Tools
    • OceanBase Cloud Platform
    • OceanBase Migration Service
    • OceanBase Developer Center
    • OceanBase Migration Assessment
    • OceanBase Admin Tool
    • OceanBase Loader and Dumper
    • OceanBase Deployer
    • Kubernetes operator for OceanBase
    • OceanBase Diagnostic Tool
    • OceanBase Binlog Service
    Connectors and Middleware
    • OceanBase Database Proxy
    • Embedded SQL in C for OceanBase
    • OceanBase Call Interface
    • OceanBase Connector/C
    • OceanBase Connector/J
    • OceanBase Connector/ODBC
    • OceanBase Connector/NET
    SQL
    KV
    • V 4.6.0
    • V 4.4.2
    • V 4.3.5
    • V 4.3.3
    • V 4.3.1
    • V 4.3.0
    • V 4.2.5
    • V 4.2.2
    • V 4.2.1
    • V 4.2.0
    • V 4.1.0
    • V 4.0.0
    • V 3.1.4 and earlier

    Connect to OceanBase Database by using the MySQLi driver

    Last Updated:2026-04-15 08:25:14  Updated
    Share
    What is on this page
    Applicable versions
    Prerequisites
    Procedure
    Step 1: Check and install the php and php-mysql environment
    Step 2: Create an obtest1.php sample file and configure the database connection information
    Step 3: Run the obtest.php file and perform verification

    folded

    Share

    This topic introduces how to build an application by using MySQLi and OceanBase Database. It also covers the use of the application for fundamental database operations, including table creation and data insertion.

    MySQLi is a PHP extension that provides procedural or object-oriented database access methods.

    Applicable versions

    This content is applicable to all versions of OceanBase Database.

    Prerequisites

    • You have installed php and php-mysql.
    • You have installed OceanBase Database and created a tenant of the MySQL mode.

    Procedure

    1. Check and install the php and php-mysql environment.
    2. Create an obtest1.php sample file and configure the database connection information.
    3. Run the obtest1.php file and perform verification.

    Step 1: Check and install the php and php-mysql environment

    For specific instructions on how to install the php and php-mysql environment, see Step 1: Check and install the php and php-mysql environment in Connect to OceanBase Database by using an EXT driver.

    Step 2: Create an obtest1.php sample file and configure the database connection information

    In the Linux environment, for example, you can use the command vi obtest1.php or vim obtest1.php to edit the obtest1.php file, and modify the database connection information in the file based on your specific needs.

    Here is an example:

    [root]# vim obtest1.php
    <?php
    $servername = "11.158.xx.xx";
    $port = "6001";
    $username = "root@mysql";
    $password = "";
    $dbname = "test";
    
    // Create a connection
    $conn = new mysqli($servername, $username, $password, $dbname, $port);
    
    // Check whether the connection is successful
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }
    
    // Create a table
    $sql = "CREATE TABLE myguests (
    id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    firstname VARCHAR(30) NOT NULL,
    lastname VARCHAR(30) NOT NULL,
    email VARCHAR(50),
    reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
    )";
    if ($conn->query($sql) === TRUE) {
        echo "Table myguests is created successfully";
    } else {
        echo "Table creation error: " . $conn->error;
    }
    
    // Insert data
    $sql = "INSERT INTO myguests (firstname, lastname, email)
    VALUES ('John', 'Doe', 'john@example.com')";
    if ($conn->query($sql) === TRUE) {
        echo "New record is inserted successfully";
    } else {
        echo "Data insertion error: " . $conn->error;
    }
    
    // Query table
    $sql = "SELECT id, firstname, lastname FROM MyGuests";
    $result = $conn->query($sql);
    
    if ($result->num_rows > 0) {
        // Output data
        while($row = $result->fetch_assoc()) {
            echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
        }
    } else {
        echo "0 result";
    }
    
    // Delete table
    $sql = "DROP TABLE myguests";
    if ($conn->query($sql) === TRUE) {
        echo "Table myguests is deleted successfully";
    } else {
        echo "Table deletion error: " . $conn->error;
    }
    
    // Close the connection
    $conn->close();
    ?>
    

    where

    • $servername indicates the IP address of the MySQL server.
    • $port indicates the port number of the MySQL server.
    • $username indicates the MySQL username for connecting to the database.
    • $password indicates the MySQL password for connecting to the database.
    • $dbname indicates the name of the database to connect to.

    Step 3: Run the obtest.php file and perform verification

    Execute the php obtest1.php command to run the obtest1.php file and check whether the connection to OceanBase Database is successful.

    Here is an example:

    [root]# php obtest1.php
    Table myguests is created successfully. New record is inserted successfully. id: 1 - Name: John Doe<br>Table myguests is deleted successfully.
    

    Previous topic

    EXT
    Last

    Next topic

    PDO
    Next
    What is on this page
    Applicable versions
    Prerequisites
    Procedure
    Step 1: Check and install the php and php-mysql environment
    Step 2: Create an obtest1.php sample file and configure the database connection information
    Step 3: Run the obtest.php file and perform verification