Search code examples
phpwindowsxamppmedoo

SELECT ALL with Medoo


I have just started using Medoo, and it seems that it's impossible to perform

SELECT * FROM users

in a simple way. I have tried using

$result = $db->select("users","*");

as the official documentation suggests, but this returned an error:

Warning: Invalid argument supplied for foreach() in medoo.php on line 746

I am aware that I can achieve what I want by typing

$result = $db->query('SELECT * FROM users')->fetchAll();

but I was wondering whether there's a simpler / shorter way to perform an ordinary Select All query in Medoo?

EDIT This my connection file.

require ('medoo.php');

define("TYPE", "mysql");
define("DATABASE", "test");
define("HOST", "localhost");
define("USER", "root");
define("PASS", "");
define("CHARSET", "utf8");

$db = new medoo (array(
    'database_type' => TYPE,
    'database_name' => DATABASE,
    'server'        => HOST,
    'username'      => USER,
    'password'      => PASS,
    'charset'       => CHARSET));

EDIT 2 The table name is users. The columns are irrelevant, but let's say that they are id, username, password, is_deleted. The strange (to me, anyway) part of it all is that a query such as

$result = $db->select('users',array('id','username'));

returns a result which I can easily printout with, say, var_dump, or a combo of echoing pre and print_r($result). It's just that simple, basic Select all that's seemingly impossible to do.

EDIT 3 I have also tried changing the quotes into apostrophes, and still no dice. If it's of importance, here are my versions of PHP, MySQL and Medoo:

PHP 5.4.31 // obtained via phpinfo
MySQL 5.5.39 // obtained by querying SELECT VERSION() in phpMyAdmin
Medoo 1.1

EDIT 4 I have had the chance of testing the problematic query on another PC, running Windows 7 Enterprise, using WAMP (forgot to check the version), PHP 5.5.31, and Medoo version 1. To my surprise, the query passes, and returns what I'd expect it to.

Back home, on my machine (using XAMPP 1.8.2-6, on Windows XP SP3 - maybe that's where the problem lies?) I used

$result = $db->debug()->select("users","*");

which resulted in

SELECT * FROM "users";

Please note the quotes. I'm guessing that this might be the culprit, since they are not present when I'm debugging the statement:

$result = $db->debug()->query('SELECT * FROM users');
//Outputs SELECT * FROM users

Solution

  • I have solved the problem by updating phpMyAdmin to version 4.4.15.7, and Medoo to version 1.1.2. Everything is working fine now.