Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 3435

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 61k
Author
Asked: November 26, 20242024-11-26T02:41:08+00:00 2024-11-26T02:41:08+00:00

ThingsDB and PHP

  • 61k

Maybe you never heard about ThingsDB. Me neither until last month. First thing should be some introduction of ThingsDB. At their website you can read:

ThingsDB logo

ThingsDB is an open-source Stored-State-Distributed-Interpreter (SSDI) solution written in the C programming language. It is designed to provide a powerful and scalable platform for storing, managing, and processing data. ThingsDB is particularly well-suited for applications that require real-time data processing, high availability, and fault tolerance.

I'm not going to lie, it seemed intruiging to me and I started thinking about what project I can build with it. But I saw immediately there are only few available drivers for communication besides standard HTTP API. I always prefer using socket connection because it's faster than making HTTP requests. It was the same case like when I decided to build client for communication with Neo4j (Bolt).

Fortunately they provide well made documentation and that made my job easier. It took few days and driver was working very well. I've learned a bit about ThingsDB while doing that, which gives me more knowledge for building my project around it. My driver is available at github as opensource: thingsdb-php.


Easiest way is to install it into your project is with composer. Driver is made with simple approach. You just create new instance of class ThingsDB. It will immediately connect to provided uri and afterwards you can start communicating with ThingsDB. In the beginning there is just few methods needed:

  • auth – most important one, you need to authorize
  • authToken – same as auth but this one is for token authorization
  • query – sending query to database
  • run – run a procedure available in database

The simplest example of using my driver looks like this:

use ThingsDBThingsDB; $thingsDB = new ThingsDB(); $result = $thingsDB->auth(); // on successful login $result will be true $message = $thingsDB->query('@:stuff', '"Hello World!";');  // $message will contain "Hello World!"  
Enter fullscreen mode Exit fullscreen mode

auth accepts arguments for username and password but ThingsDB default “admin” and “pass” is set as default value. Sending simple “Hello World!” is send back to us. But you can do way more.

There is a lot of stuff you can do directly in ThingsDB. Go ahead and check their documentation.

Let me show you another example using run method for executing procedures:

use ThingsDBThingsDB; $thingsDB = new ThingsDB(); $result = $thingsDB->auth();  // check existing procedure, destroy it if it exists $exists = $thingsDB->query('@:stuff', 'has_procedure(procName);', ['procName' => 'multiply']); if ($exists) {     $thingsDB->query('@:stuff', 'del_procedure(procName);', ['procName' => 'multiply']); } // create procedure $thingsDB->query('@:stuff', 'new_procedure(procName, |x, y| x * y);', ['procName' => 'multiply']);  // call procedure $result = $thingsDB->run('@:stuff', 'multiply', [4, 5]); // $result will be int(20) 
Enter fullscreen mode Exit fullscreen mode

For simplicity of example I'm not checking every query response and also I didn't surround the logic with try catch.

If you want to see more examples, you can head to tests directory of repository.


Are you asking what more the driver can do? ThingsDB supports rooms which you can join, leave and most importantly, you can listen for emit. This way different actions can be invoked across all connected clients. Here is a set of available methods for this:

  • join – join room(s)
  • leave – leave room(s)
  • emit – emit an event in room
  • listening – Listen for incoming events

listening should be used with caution. It will pause php execution and just waits for communication coming from database. You can decide how long you want to wait for incoming message. If you run php script with max_execution_time=0, you can even wait indefinitely.


I hope you like it and will give it a try. If you do and you would like to support me, you can give a GitHub star to my repository at thingsdb-php or you can click on donate button. Even so you if you wish to support ThingsDB you can do the same at their repository at ThingsDB.

ko-fi

I'm also working on javascript driver (link) but there is still few bumps on the road. Hopefuly it will be resolved soon.

phpprogrammingthingsdbwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    How to ensure that all the routes on my Symfony ...

    • 0 Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.