PHP MySQL Select query not returning records

PHP MySQL Select query not returning records

by Pedro Remedios -
Number of replies: 3

Hi,

I'm trying to do a simple SELECT query on a mysql table through PHP. This is the code I'm using:


    <?php

    $RTC_DB = mysqli_connect('localhost', 'root', 'telemedia-arte', 'rtc')

        or die("Erro na ligação.. ".mysqli_connect_error());

    mysqli_set_charset('utf8mb4_unicode_ci');

    if (!$RTC_DB) {

        echo "error";

    } else {

        $query = "SELECT * FROM 'prof' WHERE passo = 2";

        $videos = mysqli_query($RTC_DB, $query);

        if (mysqli_affected_rows($videos) > 0) {

            echo "Woo!";

            while ($video = mysqli_fetch_assoc($videos)) {

               $video_courses[$video["id_aula"]] = $video["tituloaula"];

            }

        }


    mysqli_close($RTC_DB);

    }

    ?>


If the query returns at least one record, it will output "Woo!", but it's not. I tried the query in phpmyadmin and it works.


Can anybody please help me with this? I'm getting very worried with this.


Thanks in advance

Pedro

Average of ratings: -
In reply to Pedro Remedios

Re: PHP MySQL Select query not returning records

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

If this is part of a Moodle project, then you really should use the Moodle DML functions - https://docs.moodle.org/dev/Data_manipulation_API

If it's not a Moodle project, then this is probably the wrong forum to be asking in ...

Average of ratings: Useful (1)
In reply to Davo Smith

Re: PHP MySQL Select query not returning records

by Pedro Remedios -

This is part of a moodle plugin actually. The code is accessing a database separate from Moodle. Could I use DML to access a database separate from Moodle?

In reply to Pedro Remedios

Re: PHP MySQL Select query not returning records

by Mike Churchward -
Picture of Core developers Picture of Plugin developers Picture of Testers

You may want to look at the core "External database" authentication plugin. It connects to a defined external database and access the data.

You can find it in "auth/db/*".

mike