prepare

PDO : prepare with bindvalue and like %

两盒软妹~` 提交于 2020-01-14 01:38:32
问题 I've looked over an hour on various website but I couldn't solve my problem. So here is the code that works: $animes = array(); $q = $this->_db->query('SELECT id, nom, nom_id FROM animes WHERE nom LIKE "%code%"'); while ($data = $q->fetch(PDO::FETCH_ASSOC)) { $animes[] = new Anime($data); } return $animes; And here is the one that doesn't work : $animes = array(); $q = $this->_db->prepare('SELECT id, nom, nom_id FROM animes WHERE nom LIKE :n'); $q->bindValue(':n',"%code%",PDO::PARAM_STR);

PDO::ATTR_EMULATE_PREPARES属性设置为false引发的血案

无人久伴 提交于 2020-01-07 12:14:07
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 前段时间给pdo设置了下emulate_prepare属性,引发了这次的血案。 在这记录下事情的经过,没准大家能避免同样的错误。 先说以下环境。php 5.2.5,mysql 5.0.81,服务器使用的GBK编码。 起因 首先是看到一个报错信息,说是sql语句的syntax error。这里给一个能重现的例子。报错的位置就是在红框的位置。 排查 从上面看,看不出语法错误。然而GBK编码的“玕”字后一个字节是0x5c,跟“\”一样。看到这,是不是就觉得这可能会有问题?但是,我记得我们是使用了pdo的prepare这种方式的(上面sql语句中我使用实际的值代替了?占位符),即使这个汉子特殊,也不会报语法错误才对。于是我翻了翻代码,发现,果然没有显示的设置PDO::ATTR_EMULATE_PREPARES属性的值。而默认是设置为true的(从字面意思就能理解,模拟prepare,不是真正意义上的prepare执行方式)。 使用tcpdump抓包,wireshark查看,确定了一下,发现果然是上面这样。 抓包的结果, 0xab5c是汉字玕的GBK编码。这里看到的是,pdo模拟处理后,多加了一个'\',而在这之前,已经告诉mysql server,客户端使用的是GBK编码(set names gbk),mysql

Qt QSqlQuery prepare and bindValue not working

雨燕双飞 提交于 2020-01-02 08:15:11
问题 I have a problem with prepare and bindValue :( db.open(); QSqlQuery q; q.prepare("SELECT id_malade,nom,prenom FROM Malade WHERE nom LIKE %:p% OR prenom = %:f% ;"); q.bindValue(":p",ui->lineEdit->text()); q.bindValue(":f",ui->lineEdit->text()); qDebug() << q.boundValue(0) << " " << q.boundValue(1); qDebug() << q.executedQuery().toStdString().c_str(); db.close(); output is: QVariant(QString, "zit") QVariant(QString, "zit") SELECT id_malade,nom,prenom FROM Malade WHERE nom LIKE %?% OR prenom = %

MySQL Select into variable

折月煮酒 提交于 2020-01-02 07:13:20
问题 I want to further use in the procedure the values I get from a select into execution but can't figure out how to do it. As a test I wrote the following but cannot use the v_1, v_2 or v_3 variables for further logic as they don't take the values 1,2 & 3 as i expected... DROP PROCEDURE IF EXISTS MPT_testing; DELIMITER // CREATE PROCEDURE MPT_testing() READS SQL DATA BEGIN DECLARE v_1 INT; DECLARE v_2 INT; DECLARE v_3 INT; SET @sql=CONCAT('SELECT 1,2 into v_1, v_2'); PREPARE s1 FROM @sql;

php MySqli : How can i rewrite fetch to fetch_assoc? LIKE CONCAT

家住魔仙堡 提交于 2019-12-30 11:11:16
问题 Helo, I using "bind_result", "LIKE CONCAT" ... to reach full text search and pagination by two query string. but how can I change bind_result methods to fetch_assoc? <?php $mysqli = new mysqli("localhost", "", "", "test"); $query_string="hello"; //keywords $sqltxt="SELECT * FROM `table` WHERE text1 LIKE CONCAT('%', ?, '%')"; //first query : for get the total number of data $stmt = $mysqli->prepare($sqltxt); $stmt->bind_param("s",$query_string); $stmt->execute(); $stmt->store_result(); $total

php unsuccessful while loop within prepared statements

﹥>﹥吖頭↗ 提交于 2019-12-25 04:07:26
问题 code below is a part of my sitemap.xml file. My aim is to write the last modified date of my approved articles. There are 2 possibilities for this data. If article has no approved comment, then lastmod is the approval date of the article. If article has at least 1 approved comment, then lastmod is the approval date of the last approved comment. Errors in my output are: There are some articles in my db that has no comments but also these commentless articles get the approval date of last

PHP Call to a member function prepare() on a non-object error

与世无争的帅哥 提交于 2019-12-25 02:16:15
问题 Hi i need some help with this error I keep getting. It works fine everywhere else in the script except when I try to call it within this one function. The function I am calling is: getTotalServers Error: Fatal error: Call to a member function prepare() on a non-object in C:\xampp2\htdocs\runeloft\ss_sources\util.php on line 208 Calling in this function: function display_table($online, $where, $num_servers = null){ global $aaaa, $bbbb; $num_per_page = 30; $page = 1; // how many records per

android java mediaplayer Service - how can I know if mediaPlayer is prepared?

北城余情 提交于 2019-12-24 10:36:27
问题 I made a binded service with MediaPlayer controls which loads and play back audio. But as it happens, sometimes mediaPlayer.prepare(); is not fast enough and it's not always prepared to playback. So how can I make such method , something like myService.prepare() where I can ask for MediaPlayer to prepare and wait for it? 回答1: You may wait for the OnPrepared event to be triggered by the MediaPlayer. http://developer.android.com/reference/android/media/MediaPlayer.OnPreparedListener.html Edit :

MediaPlayer sometimes not preparing when screen is locked

爷,独闯天下 提交于 2019-12-22 10:23:37
问题 I have a MusicService for MediaPlayback, wich uses a MediaPlayer with the settings: player.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK); player.setAudioStreamType(AudioManager.STREAM_MUSIC); and those Listeners are set: OnPreparedListener, OnCompletionListener, OnErrorListener, OnSeekCompleteListener The MediaPlayer is used for mp3-Playback. When one Song is finished, onCompletion is called. Then PlayNext is called, wich resets the MediaPlayer, then sets the Datasource

Commit some files while maven release:prepare

*爱你&永不变心* 提交于 2019-12-21 16:49:32
问题 Is it possible to commit some file (no pom.xml) while mvn release:prepare? In My MultiModul Project I configured the rlease plugin with preparationGoals to change the Version in a sql file. <preparationGoals>clean verify org.codehaus.mojo:build-helper-maven-plugin:1.5:parse-version com.google.code.maven-replacer-plugin:replacer:1.5.0:replace</preparationGoals> Everything works fine but the changed sql File will not be commited. The sql File is in a subdirectory of the parent Folder. There are