prepared-statement

PHP & MySQL: zerofill is lost when using mysqli->prepare()

故事扮演 提交于 2019-12-14 03:23:00
问题 Using: MySQL 5.1 + PHP 5.3.5 MySQL: id in "table" is defined as: mediumint(6) zerofill not null I get the expected result when using: $mysqli->query("SELECT id FROM table WHERE id = 1"); while($row = $ret->fetch_array(MYSQLI_ASSOC)) $arr[] = $row; >>> $arr[0]["id"] = 000001 But not when I use prepared statement: $ret = $mysqli->prepare("SELECT id FROM table WHERE id = ?"); call_user_func_array(array($ret,"bind_param"),array("i",1)); $ret->execute(); $ret->store_result(); $meta = $ret->result

Prepared statement execute fatal error and variables and database table miss match

ⅰ亾dé卋堺 提交于 2019-12-14 03:15:18
问题 I get the following error Fatal error: Call to a member function execute() on a non-object in /home/wt/public_html/view-reports.php on line 237 . I also see another problem. The variables generated doesn't echo the right corresponding data. For instance, $rep_type echo position. Could you please help me on this. Thank you! Test site url is here. ethioserver.com/~wt/view-reports.php?rep_id=144 The problem is not visible in wampserver. The php version in both servers is 5.4. The main code is

Saving the output of a dynamic query that uses prepare statement into a table

时光怂恿深爱的人放手 提交于 2019-12-14 03:04:25
问题 In continuation to a previous case (a solution by @Erwin Brandstetter), in which a dynamic SELECT query that uses a 'prepare' statement was created and then was executed by calling it, as below: --the function for making the prepare statement: CREATE OR REPLACE FUNCTION f_prep_query (_tbl regclass, _prefix text) RETURNS void AS $func$ DECLARE _prep_qry text := ( SELECT 'PREPARE stmt_dyn AS SELECT ' || string_agg(quote_ident(attname), ',' ORDER BY attname) || ' FROM ' || _tbl FROM pg_attribute

Performance impact of empty LIKE in a prepared statement

落爺英雄遲暮 提交于 2019-12-14 02:37:58
问题 I have set a GiST pg_trgm index on the name column of the files table. The simplified query of the prepared statement looks like this: SELECT * FROM files WHERE name LIKE $1; The $1 param will be composed of % + user query + % . Since the input might also be an empty string this might result in %% . Does an "empty" LIKE ( %% ) result in performance degradation? Should I build a new query in that case, or does it not matter? 回答1: Postgres 9.2 or later is generally smart enough to realize that

PHP\MYSQL prepared statements

北战南征 提交于 2019-12-14 00:29:36
问题 I'm new to mysql and php and wanted to clarify something on prepared-statements. All the examples I've seen only add params for the actual data in the table, is it bad practice to paramaterise all the fields so there are less statements? e.g. UPDATE ? SET ?=? WHERE ID=? Thank you 回答1: You cannot parameterize identifiers. You can only parameterize data . Otherwise the main point of parameterization, the separation between statement structure and data , is pretty moot. Understand that

java,mysql insert into multiple tables using preparedStatement

自古美人都是妖i 提交于 2019-12-13 22:00:21
问题 Ok, going to reword this question as i made it a bit too complicated before. i want to take this: con.setAutoCommit(false); String tempforbatch; Statement stmt = con.createStatement(); for (int i = 0; i < tables.length; i++) { tempforbatch = "INSERT INTO " + tables[i] + " VALUES ('" + values[i] + "')"; stmt.addBatch(tempforbatch); } stmt.executeBatch(); and turn it into something exactly the same, only using: PreparedStatement stmt = con.prepareStatement("INSERT INTO table_name VALUES (?, ?)"

Using query_to_xml in PostgreSQL with prepared statements

左心房为你撑大大i 提交于 2019-12-13 21:28:12
问题 I'm using PostgreSQL's function query_to_xml function to generate XML of a query result. SELECT * FROM query_to_xml( 'SELECT * from some_table WHERE id = ?',true,false,'') Problem is, when I use it from JDBC, with prepared Statements the '?' is ignored, so Postgres says: "The column index is out of range..." Is there any possible solution to pass parameters to such a query ? 回答1: Try to move the ? outside the string literal: SELECT * FROM query_to_xml( 'SELECT * from some_table WHERE id = '||

Issue with passing column name as a parameter to “PREPARE” in Redshift

不问归期 提交于 2019-12-13 20:10:30
问题 I am using REDSHIFT for the below question, Here is problem and I am looking for solution. I have 2 tables, one table contains the column combinations on which the second table should group the results by. Table 1 containing column combinations (This is output from a stored procedure): COMBINATIONS fruit_combinations banana,'ALL' banana, orange Table 2 containing fruit_baskets: FRUIT_BASKET BANANA ORANGE USER_COUNT b1 o1 5 b1 o2 10 Result set: FRUIT_BASKET_AGG BANANA ORANGE USER_COUNT b1 'ALL

Prepared statement not letting me call $mysqli->stmt_init()

梦想与她 提交于 2019-12-13 16:13:43
问题 I have done this before but am quite new to mysqli and prepared statements (as I'm sure you can see from this issue). Where am I going wrong? here is my connection function (part of the 'Connect' class) public function site_db() { // Connect to MySQL $link = mysqli_connect(SITE_HOST, SITE_ID, SITE_PW, SITE_DB); // Check for Errors if(mysqli_connect_errno()) { //echo mysqli_connect_error(); //shouldnt show client specific error information. die('Error connecting to mysql database please report

How to check whether Prepared Statement has some batches or not, before executeBatch()?

你。 提交于 2019-12-13 14:26:43
问题 I have a doubt related to Prepared Statement in Java as I don't know much about it. I have a use case in which I have to use PreparedStatement. But I am just thinking before writing code that: while(...) { if(...) { preparedStatement.setString(1, fname); preparedStatement.setString(2, lname); ... preparedStatement.addBatch(); } } preparedStatement.executeBatch(); Lets Consider the above code. There is a while loop which will do some stuff and then check some condition and then add the batch