• Resolved k44g

    (@k44g)


    This is a question about using WPCode to include PHP on WordPress website.

    I implement websites in PHP and often use MySql databases and access tables using queries within PHP scripts. For example, this lists all rows in a table (derived from an actual PHP script):

    <?php
    include("/srv/www/.....") [ [this opens and connects the table]
    $query="SELECT * FROM TABLE_NAME; ";
    $result=mysqli_query($connect, $query);
    while($row=mysqli_fetch_assoc($result)) {
    echo $row['ID'];
    echo $row[NAME]:
    [and additional fields]
    }
    ?>

    FWIW, this is extracted from a code module of a website running on a Linux server and Apache.

    Will this work with WPCode?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @k44g,

    The type of code you mentioned should work without an issue in a PHP snippet added through WPCode. The only thing to keep in mind is that you are better off using the ABSPATH constant for the include path so that you don’t run into errors.

    In WordPress, in general it’s recommended to use the wpdb class to access the database to make things safer.

    • This reply was modified 4 months, 1 week ago by Mircea Sandu. Reason: typo
    Thread Starter k44g

    (@k44g)

    Thank you for that clear response.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.