Petit soucis sql
Tsunami Chups
Messages postés
237
Statut
Membre
-
Tsunami Chups Messages postés 237 Statut Membre -
Tsunami Chups Messages postés 237 Statut Membre -
Bonjour,
J'ai une erreur dans ma requete sql mais je ne vois pas ou ^^'
une erreur bete probablement mais ... genante
voila mon code :
Et voila l'erreur :
J'ai une erreur dans ma requete sql mais je ne vois pas ou ^^'
une erreur bete probablement mais ... genante
voila mon code :
$this->_helper->viewRenderer->setNoRender();
$nberrors = 0;
$return = array();
$errors = array();
$params = array();
$recherche = $_POST['recherche'];
if ($this->_hasParam('start'))
{
$start = $this->_getParam('start');
if (!intval($start))
$start = 0;
}
else
$start = 0;
// initialize the parameter limit (number of results)
if ($this->_hasParam('limit'))
{
$nbresults = $this->_getParam('limit');
if (!intval($nbresults))
$nbresults = 25;
}
else
$nbresults = 25;
$album = new AlbumModel;
$params = array();
/*$params['keyword'] = $this->_getParam('keyword');
$params['artist_id'] = $this->_getParam('artist_id');
$params['album_id'] = $this->_getParam('albumId');
$params['track_id'] = $this->_getParam('trackId');
$params['backstage_category'] = $this->_getParam('backstage_category');
$params['news_type_search'] = $this->_getParam('news_type_search');
$params['date_from'] = $this->_getParam('date_from') ? $this->_getParam('date_from') : $this->_getParam('date_begin');
$params['date_to'] = $this->_getParam('date_to') ? $this->_getParam('date_to') : $this->_getParam('date_end');
$params['sort'] = $this->_getParam('sort');
$params['dir'] = $this->_getParam('dir');*/
$select = $album->prepareSelect($params); //utilisation de la fonction prepareSelect de la page NewModel
$select->reset(Zend_Db_Select::COLUMNS);
$select->columns(array('am_album.*')); //definition de la table ou prendre les donner
$select->distinct();
$select->limit($nbresults, $start);
//$select->where('id ='.$recherche);
//$select->where('name = "'.$recherche.'"');
$select->where('name LIKE = '.$recherche);
//$select->where('name LIKE ? ', $recherche);
print $select or die(mysql_error());
$found = $album->fetchAll($select);
$return['totalCount'] = $album->getCount($select);
$columns = array('id','name');
$return['records'] = $found->toArrayColumns($columns);
$return['errors'] = $errors;
$return['nberrors'] = $nberrors;
$this->getResponse()->setHeader('Content-Type', 'text/javascript');
Zend_Loader::loadClass('Zend_Json');
$json = Zend_Json::encode($return);
$this->getResponse()->setBody($json);
Et voila l'erreur :
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= king) ORDER BY `am_album`.`name` ASC LIMIT 25' at line 1 Stack Trace: #0 C:\Documents and Settings\TsunamiChups\workspace\allomusicv1\application\library\Zend\Db\Statement.php(303): Zend_Db_Statement_Pdo->_execute(Array)\n#1 C:\Documents and Setting
A voir également:
- Petit soucis sql
- Petit point vert snap ✓ - Forum Snapchat
- Petit 2 ✓ - Forum Windows
- Trier du plus petit au plus grand excel - Guide
- Point vert sur Snapchat - Forum Snapchat
- Comment imprimer une photo en petit ✓ - Forum Photo numérique
2 réponses
Hello
J'ai pas trop l'habitude de MySQL et encore moins de ton mode opératoire... mais l'erreur ne serait-elle tout simplement pas au niveau du like
primo: ton critère de recherche n'est pas encadré par des apostrophes
secundo: l'opérateur LIKE est exclusif de l'opérateur = => tu devrais avoir
$select->where("name LIKE '" . $recherche . "%'");
ou qqe chose dans le genre !
... et le % est là pour la correspondance partielle
J'ai pas trop l'habitude de MySQL et encore moins de ton mode opératoire... mais l'erreur ne serait-elle tout simplement pas au niveau du like
$select->distinct();
$select->limit($nbresults, $start);
$select->where('name LIKE = '.$recherche);
primo: ton critère de recherche n'est pas encadré par des apostrophes
secundo: l'opérateur LIKE est exclusif de l'opérateur = => tu devrais avoir
$select->where("name LIKE '" . $recherche . "%'");
ou qqe chose dans le genre !
... et le % est là pour la correspondance partielle