Medoo icon indicating copy to clipboard operation
Medoo copied to clipboard

medoo::insert() issue

Open junpengli opened this issue 13 years ago • 3 comments

Hello,

Thank you for this nice framework. My english is very bad, Can you understand what I mean?

$config = require_once 'config.php';
require_once 'medoo.php';
$db = new medoo($config['DB']);
$query = $db->insert("sdfasdfa",array("sdf" => 1));
var_dump($db->error());

if table not exists, can not find error!

public function insert($table, $data)
{
    $keys = implode(',', array_keys($data));
    $values = array();
    foreach ($data as $key => $value)
    {
        $values[] = is_array($value) ? serialize($value) : $value;
    }
    return $this->query('INSERT INTO ' . $table . ' (' . $keys . ') VALUES (' . $this->data_implode(array_values($values), ',') . ')');
}

function lastInsertId()
{
    return $this->pdo->lastInsertId();
}

junpengli avatar May 30 '13 10:05 junpengli

If insert data into table that did not exist, the return data will be 0.

$last_id = $databbase->insert("table",array("foo" => "bar"));
var_dump($last_id); // == '0'

catfan avatar May 30 '13 10:05 catfan

But I want to know why ? I want to know why it is 0,What happened on my sql.

junpengli avatar May 31 '13 00:05 junpengli

On Medoo 0.8.5, you can output the error by $database->error() if you insert data into the table doesn't exist.

catfan avatar Jul 21 '13 10:07 catfan