Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A simple PHP application that connects to a YugabyteDB database cluster and performs basic CRUD operations.

License

NotificationsYou must be signed in to change notification settings

YugabyteDB-Samples/yugabyte-simple-php-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

This application connects to your YugabyteDB instance via thephp-pgsql driver for PostgreSQL and performs basic SQL operations. The instructions below are provided forYugabyteDB Aeon deployments.If you use a different type of deployment, then update thesample-app.php file with proper connection parameters.

Prerequisite

  • PHP runtime - the sample project was created with PHP 8.1 but should work with earlier and later versions.
  • Command line tool or your favorite IDE, such as Visual Studio Code.

Start YugabyteDB Aeon Cluster

Clone Application Repository

Clone the repository and change dirs into it:

git clone https://github.com/YugabyteDB-Samples/yugabyte-simple-php-app.git&&cd yugabyte-simple-php-app

Provide YugabyteDB Aeon Connection Parameters

Set the following connection parameters in thesample-app.php file:

  • HOST - the hostname of your YugabyteDB Managed instance.
  • USER - the username for your database.
  • PASSWORD - the password for your database.
  • SSL_MODE - an SSL mode. Make sure it's set toverify-full for YugabyteDB Aeon.
  • SSL_ROOT_CERT - a full path to your CA root cert (for example,/Users/dmagda/certificates/root.crt).

Note, you can easily find all the settings on the YugabyteDB Aeon dashboard:

image

Run the Application

  1. Install thephp-pgsql driver:

    • Homebrew users of version PHP 7.2+: the driver is installed automatically with thebrew install php command.
    • Ubuntu users can install with thesudo apt-get install php-pgsql command.
    • CentOS users can install with thesudo yum install php-pgsql command.
    • Others need to follow thephp-pgsql installation guide.
  2. Run the application:

    php sample-app.php

Upon successful execution, you will see output similar to the following:

>>>> Connecting to YugabyteDB!>>>> Successfully connected to YugabyteDB!>>>> Successfully created table DemoAccount.>>>> Selecting accounts:name=Jessica, age=28, country=USA, balance=10000name=John, age=28, country=Canada, balance=9000>>>> Transferred 800 between accounts>>>> Selecting accounts:name=Jessica, age=28, country=USA, balance=9200name=John, age=28, country=Canada, balance=9800

Explore Application Logic

Congrats! You've successfully executed a simple PHP app that works with YugabyteDB Aeon.

Now, explore the source code ofsample-app.php:

  1. connect function - establishes a connection with your cloud instance via the php-pgsql driver.
  2. create_database function - creates a table and populates it with sample data.
  3. select_accounts function - queries the data with SQLSELECT statements.
  4. transfer_money_between_accounts function - updates records consistently with distributed transactions.

Questions or Issues?

Having issues running this application or want to learn more from Yugabyte experts?

Joinour Slack channel,or raise a question on StackOverflow and tag the question withyugabytedb!

About

A simple PHP application that connects to a YugabyteDB database cluster and performs basic CRUD operations.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp