gpt4 book ai didi

cakephp - mysql-real-escape-string : Access denied in CakePHP

转载 作者:行者123 更新时间:2023-12-02 06:39:33 25 4
gpt4 key购买 nike

在使用 CakePHP 将数据保存到我的数据库之前,我尝试使用 mysql-real-escape-string 对输入进行清理。我收到以下错误

mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'nobody'@'localhost' (using password: NO)

我的代码:

public function admin_videos($id = null) {
if(!($this->isLogged() && $this->isAuthorized())) {
$this->redirect(array('controller' => 'users', 'action' => 'login', 'admin' => true));
}
if ($this->request->is('post')) {
$this->request->data['MovieVideo']['video'] = mysql_real_escape_string($this->request->data['MovieVideo']['video']);
$this->request->data['MovieTrailer']['video'] = mysql_real_escape_string($this->request->data['MovieTrailer']['video']);
if ($this->Movie->saveAll($this->request->data)) {
$this->Session->setFlash('The movie has been saved', 'admin/flash_success');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('The movie could not be saved. Please, try again.', 'admin/flash_error');
}
} else {
$this->request->data = $this->Movie->find('first', array('conditions' => array('Movie.id' => $id), 'contain' => array('MovieTrailer', 'MovieVideo')));
}
}

最佳答案

来自docs :

CakePHP already protects you against SQL Injection if you use CakePHP's ORM methods (such as find() and save()) and proper array notation (ie. array('field' => $value)) instead of raw SQL.

所以忘记手动调用 mysql_real_escape_string()

关于cakephp - mysql-real-escape-string : Access denied in CakePHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10732600/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com