how to make

how can I add data to a table in my database with elgg?
  • There can be two scenario.. 1st you have two separate database i.e "my database" and "elgg database" or 2nd.. you have one database where you have all the table combined for both "my database" and "elgg database".

    Scenario 1: In this case you can access your database just like you access any database from a php file:

    <?php
    $servername = "localhost";
    $username = "username";
    $password = "password";
    
    // Create connection
    $conn = new mysqli($servername, $username, $password);
    
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } 
    echo "Connected successfully";
    ?>

    More details at: https://www.w3schools.com/php/php_mysql_connect.asp

    Scenario 2: You can use elgg's function like getData, getDataRow, insertData etc to execute your query. However, it is not recommended to modify the default database structure unless you are absolutely sure of what you are doing.

    In Elgg, everything runs on a unified data model based on atomic units of data called entities and you can create almost anything using elgg. Plugins are discouraged from interacting directly with the database, which creates a more stable system and a better user experience because content created by different plugins can be mixed together in consistent ways. With this approach, plugins are faster to develop, and are at the same time much more powerful. It is highly recommended that you use elgg feature and try to utilise it to the fullest.

  • Best would be to read the docs, e.g. http://learn.elgg.org/en/stable/design/database.html and http://learn.elgg.org/en/stable/design/index.html and http://learn.elgg.org/en/stable/guides/index.html. "Adding data to a table" is rather unspecific, so it's impossible to give you any good advice. The point is: depending on what kind of data you want to add it's very likely that you will find at least some basic advice in the docs or you could study the code of existing plugins to see how it's done. You should do it as already done by Elgg in plugins using Elgg API functions wherever possible and not trying to write anything directly to the database without knowing exactly what you are doing.