MySQL query with medoo

0

Situation

I'm going to pass a project that uses obsolete mysql queries (from the mysql_query or mysql_connect ) to the Medoo framework so that it works correctly in PHP7.

Problem

I was not very familiar with this framework, and doing some previous tests I have encountered this problem; I have created a function that receives the name of a table, the name of a field and an id number. Returns the value of the field it receives.

I will omit the part of the connection to the database because I have already verified its correct operation:

function devuelve_dato_sql($tabla, $campo, $id) {
    global $db;

    $data=$db->select($tabla,$campo,
        ['AND' => ['id' => $id]
        ]
    );
    return $data[0][$campo];
}

//Llamada a la función
$data=devuelve_dato_sql("usuarios","nombre","1");
echo $data; // "S"
var_dump($data); // string(1) "S"

The problem, as you see in the comments, is that instead of returning the full name, I only receive the first character, what am I missing?

Edit

I tried to put the medoo tag but I can not because it does not exist and I still do not have the necessary reputation to create it.

    
asked by Hechi 19.07.2016 в 13:33
source

1 answer

0

Solved!

In the return of the function I had this:

return $data[0][$campo];

When the correct syntax would be:

return $data[0];

    
answered by 19.07.2016 / 13:41
source