The exec function is used to evaluate a command at the system level ie. terminal. What you’re doing makes no sense in that regards. You need to use a MySQL adapter to issue a query to MySQL and return a result set. Preferably you would use PDO to connect to the database than execute a query.
<?php // outputs the username that owns the running php/httpd process // (on a system with the "whoami" executable in the path) echo exec('whoami'); ?>
I’m using XAMPP as a local host with Apache and MySQL; could this be the problem? Everything works OK using the MySQL control panel so could there be a link missing or incomplete?
Maybe the ORDER BY is causing a problem?
Since it isn’t important you might as well remove it.
And there is no need to SELECT everything, the one field would be enough.
Try this simplified query SELECT lecturedate FROM lectures
Thanks Mittineague, but that would not give me what I am looking for. I am trying to sort the records in the lecturedate column; “SELECT lecturedate FROM lectures” will simply give me a list of lecturedate records.
Then, from the documentation you posted a link to, you do not want to use exec
For a SELECT statement that you only need to issue once during your program, consider issuing PDO::query(). For a statement that you need to issue multiple times, prepare a PDOStatement object with PDO::prepare() and issue the statement with PDOStatement::execute().
According to that link you posted though, exec() doesn’t return the records anyway (“PDO::exec() does not return results from a SELECT statement.” it says), you need to use query() or prepare() and execute() for that. exec() would be used for something like updating or deleting a value, not extracting data. I think @mittineague was suggesting dropping the ORDER BY clause to see if that was causing the problem.
Here is the code I’m running. I know from the output that it is working OK (htmlout() is a helper function to safely print to monitor). What I had hoped was that the re-ordered data would update the lectures table in the database, which is accessed via $pdo. However, this is not happening.