mysql int保存数据技巧
程序员文章站
2022-05-30 21:11:06
...
public function insert($data)
{
if(isset($data['content'])&&!empty($data['content']))
{
$data_for_query['content'] = trim($data['content']);
}
else
{
return false;
}
if(isset($data['user_id'])&&!empty($data['user_id']))
{
$data_for_query['user_id'] = intval($data['user_id']);
}
else
{
return false;
}
$sql = "insert into `".$this->table_name."` (".$this->db->implodetocolumn(array_keys($data_for_query)).") values (".$this->db->implodetovalues(array_values($data_for_query)).")";
$this->db->query($sql);
$id = $this->db->lastinsertid();
if(empty($id))
{
return false;
}
else
{
return $id;
}
}
{
if(isset($data['content'])&&!empty($data['content']))
{
$data_for_query['content'] = trim($data['content']);
}
else
{
return false;
}
if(isset($data['user_id'])&&!empty($data['user_id']))
{
$data_for_query['user_id'] = intval($data['user_id']);
}
else
{
return false;
}
$sql = "insert into `".$this->table_name."` (".$this->db->implodetocolumn(array_keys($data_for_query)).") values (".$this->db->implodetovalues(array_values($data_for_query)).")";
$this->db->query($sql);
$id = $this->db->lastinsertid();
if(empty($id))
{
return false;
}
else
{
return $id;
}
}
上一篇: 写了个遍历目录、批量替换文件内容的类
下一篇: 在PHP中结果集,该如何解决