General developer forum

PHP MySQL Select query not returning records

 
Picture of Pedro Remedios
PHP MySQL Select query not returning records
 

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: -
Davo
Re: PHP MySQL Select query not returning records
Group Core developersGroup Particularly helpful MoodlersGroup 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)
Picture of Pedro Remedios
Re: PHP MySQL Select query not returning records
 

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?

 
Average of ratings: -
Picture of Mike Churchward
Re: PHP MySQL Select query not returning records
Group Core developersGroup Particularly helpful MoodlersGroup Plugin developersGroup Plugins guardiansGroup 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

 
Average of ratings: -