All Products
Search
Document Center

Lindorm:Develop applications using PHP

Last Updated:Mar 28, 2026

Connect a PHP application to LindormTable using the MySQLi extension and Lindorm SQL over the MySQL-compatible endpoint.

Prerequisites

Before you begin, ensure that you have:

Install the php-mysql module

Install the php-mysql module before connecting to LindormTable. For installation instructions, see PHP installation.

Configure connection parameters

Get the MySQL-compatible endpoint for your Lindorm instance. See View connection addresses.

Configure the following connection parameters in your PHP code:

$lindorm_addr="ld-uf6k8yqb741t3****-proxy-sql-lindorm-public.lindorm.rds.aliyuncs.com";
$lindorm_username="user";
$lindorm_password="test";
$lindorm_database="default";
$lindorm_port=33060;

Connection parameters

ParameterDescription
$lindorm_addrThe MySQL-compatible endpoint for LindormTable. See View connection addresses to find the endpoint. Use the VPC address when your application runs on an ECS instance, and the Internet address when connecting over the public network.
$lindorm_usernameThe username for LindormTable. To reset a forgotten password, see Change a user password.
$lindorm_passwordThe password for the LindormTable user.
$lindorm_databaseThe database to connect to. The default database is default.
$lindorm_portThe MySQL protocol port. Fixed at 33060.
Important

Choose the right endpoint type for your network:

  • ECS (VPC): Connect over a virtual private cloud (VPC) for higher security and lower latency. Set $lindorm_addr to the MySQL-compatible VPC address.

  • Local or remote (public network): Enable the public endpoint first. In the Lindorm console, go to Database Connections > Wide Table Engine and click Enable Public Endpoint. Then set $lindorm_addr to the MySQL-compatible Internet address.

Full example

The following example connects to LindormTable, creates a table, inserts a row using upsert into, and queries the data.

<?php

// The MySQL-compatible endpoint for LindormTable.
$lindorm_addr="ld-uf6k8yqb741t3****-proxy-sql-lindorm-public.lindorm.rds.aliyuncs.com";
// The username for the LindormTable connection.
$lindorm_username="user";
// The password for the LindormTable connection.
$lindorm_password="test";
// The name of the database to connect to.
$lindorm_database="default";
// The port for the MySQL protocol of LindormTable.
$lindorm_port=33060;

// Connect to LindormTable.
$lindorm_conn = mysqli_connect(
    $lindorm_addr,
    $lindorm_username,
    $lindorm_password,
    $lindorm_database,
    $lindorm_port
);
if (!$lindorm_conn) {
    printf("Can't connect to Lindorm Server. Errorcode: %s \n", mysqli_error($lindorm_conn));
    exit;
} else {
    printf("connect to Lindorm successfully\n");
}

// Create a table.
$create_table = "create table if not exists user_test(id int, name varchar, age int, primary key(id))";
if (mysqli_query($lindorm_conn, $create_table)) {
    printf("create table successfully\n");
} else {
    printf("create table error: %s \n", mysqli_error($lindorm_conn));
    exit;
}

// Insert data. LindormTable uses "upsert into" instead of standard INSERT INTO.
$insert_sql = "upsert into user_test(id, name, age) values(1, 'zhangsan', 17)";
if (mysqli_query($lindorm_conn, $insert_sql)) {
    printf("insert data successfully\n");
} else {
    printf("insert data error: %s \n", mysqli_error($lindorm_conn));
    exit;
}

// Query data.
$select_sql = "select * from user_test";
$result = mysqli_query($lindorm_conn, $select_sql);
while ($row = mysqli_fetch_array($result)) {
    printf("id %d\n", $row["id"]);
    printf("name %s\n", $row["name"]);
    printf("age %d\n", $row["age"]);
}

?>

Expected output:

connect to Lindorm successfully
create table successfully
insert data successfully
id 1
name zhangsan
age 17

How the example works

Each block in the example performs a distinct operation:

  • Connect: mysqli_connect() opens a connection using the MySQL-compatible endpoint and the fixed port 33060.

  • Create table: The CREATE TABLE IF NOT EXISTS statement creates user_test with id as the primary key. The statement is idempotent — running it multiple times does not raise an error.

  • Insert data: LindormTable uses upsert into instead of standard INSERT INTO. If a row with the same primary key already exists, the upsert updates it.

  • Query data: mysqli_query() returns a result set. mysqli_fetch_array() iterates over the rows, with column values accessed by name.

What's next