How do I connect to, read within and write within, a database in Construct 3?

1 favourites
  • 7 posts
From the Asset Store
Casino? money? who knows? but the target is the same!
  • Hello,

    I'm looking at the moment for a way to connect a database towards my project.

    My goal is it that if I enter for example a string/number I'll get reported back another string/number that is attached to this one.

    At the same time, I'm looking for a way to enter for example two strings and save them together as being attached to each other. And when searched for one of them, it'll just like above mentioned show the attached string to this one.

    Is this somehow possible? And if so, could anyone give me an insight in how I could do it or an tutorial?

    Hopefully people understand what I mean.

    Thanks in advance for answers,

    Oishii

  • I wasn't able to find an edit option for my post, so to further specify what I am looking for and people understand it hopefully easier:

    I would really appreciate any help I can get,

    Oishii

  • You can connect and interact with an hosted database like mySQL via php through the AJAX plugin's post and get action. That would require some knowledge of php and mysql, as well as having access to a dedicated web host.

    Otherwise, for the use case you have described, the dictionary object may suffice. It can associate a string (key) with any other string (value). You might need to use two dictionary objects that are mirrors of each other to get two way lookup or simply add two entries for each key-value pair, as normally it is one way. This doesn't come anywhere close to the full functionality of an actual database though.

  • You can connect and interact with an hosted database like mySQL via php through the AJAX plugin's post and get action. That would require some knowledge of php and mysql, as well as having access to a dedicated web host.

    Otherwise, for the use case you have described, the dictionary object may suffice. It can associate a string (key) with any other string (value). You might need to use two dictionary objects that are mirrors of each other to get two way lookup or simply add two entries for each key-value pair, as normally it is one way. This doesn't come anywhere close to the full functionality of an actual database though.

    Thank you for your answer, I appreciate it a lot.

    Is there any resources to learn how to do that with PHP & MySQL? I'm having a dedicated webhost and would like to try it that way. Unfortunately so far I'm having not much or rather not any knowledge in PHP or MySQL.

    Or would you rather recommend me trying it with the Dictionary object?

    Best regards and thanks in advance for answers,

    Oishii

  • If what you described is the limit of what you need (looking up pairs of strings), I would recommend trying with the dictionary object.

    When entering a pair of strings "A" and "B", create a key:value pair in dictionary 1 as "A":"B", and dictionary 2 as "B":"A". When looking up a string, you can check if key exists in either dictionary, and display both values if it does.

    Php and MySQL are quite large topics, and I'm sure you can find extensive resources with a quick Google search. I don't have any particular one to recommend.

  • To be honest I started with this https://www.construct.net/en/tutorials/online-high-score-table-ajax-202

    You will have to adapt it to Mysqli, but this will give you the insight of how to interact with a database

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I did it sucessfully with the Dictionary method being mentioned by oosyrag.

    To ensure no data is lost, I'm using a savegame as a kinda local database.

    It's a workaround compared to a real database, but so far it works.

    Thanks for all the answers and especially thanks to oosyrag.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)