Medoo
Medoo copied to clipboard
medoo::insert() issue
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();
}
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'
But I want to know why ? I want to know why it is 0,What happened on my sql.
On Medoo 0.8.5, you can output the error by $database->error() if you insert data into the table doesn't exist.