prepared-statement

How to use IN clause with PreparedStatement in PostgreSQL

爱⌒轻易说出口 提交于 2019-12-18 06:45:24
问题 I have to write a SQL query for Postgres database as follows: DELETE FROM employee WHERE ename IN (?) I want to pass ename as list or string which will contain multiple employee names, e.g. "abc, bcd, efg" . How to set the values? How to use IN clause with PreparedStatement in Postgres? 回答1: There are several ways to do this. The clean way is to pass an array to the prepared statement. An alternative to Nick's answer is to pass a proper java.sql.Array value: PreparedStatement pstmt =

PHP- inserting binary data in mysql using prepared statements

给你一囗甜甜゛ 提交于 2019-12-18 04:38:17
问题 I have to insert a row using php's mysql improved library to a table in mysql that has its primary key of type VARBINARY. The contents of this field are a computed sha1 hash. If I run the query the old way it works perfectly: $mysqli->$query("INSERT INTO table (id, field1) VALUES (0x" . $id . ",'" . $field1 . "')"); But when I try to execute it as a prepared statement, I can't figure out how to do it. If I perform the equivalent action: if($stmt = $mysqli->prepare("INSERT INTO table (id,

MySQLI Prepared Statement: num_rows & fetch_assoc

*爱你&永不变心* 提交于 2019-12-18 04:13:02
问题 Below is some poorly written and heavily misunderstood PHP code with no error checking. To be honest, I'm struggling a little getting my head around the maze of PHP->MySQLi functions! Could someone please provide an example of how one would use prepared statements to collect results in an associative array whilst also getting a row count from $stmt? The code below is what I'm playing around with. I think the bit that's throwing me off is using $stmt values after store_result and then trying

What are client-side prepared statements?

核能气质少年 提交于 2019-12-18 03:51:09
问题 Trying to learn something new - specifically trying to choose wether to use MySQLi or PDO for future projects when working with MySQL - I stumbled upon this page which shows an overview of options available to me. At the bottom of this page is a table comparing functionality of the three main methods of communicating with mysql. In the row " API supports client-side Prepared Statements ", it says that PDO supports this and MySQLi doesn't. I know what prepared statements are. The answer to

Fatal error: Call to undefined method mysqli_stmt::get_result() [duplicate]

时光总嘲笑我的痴心妄想 提交于 2019-12-17 21:05:14
问题 This question already has answers here : Call to undefined method mysqli_stmt::get_result (10 answers) Closed 4 years ago . Since i've moved a site of mine to a new vServer, I always get this error message Fatal error: Call to undefined method mysqli_stmt::get_result() These lines of code are working fine $mysql = new mysqli($db_host, $db_user, $db_password, $db_database); $partys = NULL; $res_partys = $mysql->query("SELECT * FROM party ORDER BY begin"); while($row_partys = $res_partys->fetch

store_result() and get_result() in mysql returns false

房东的猫 提交于 2019-12-17 20:52:09
问题 I made a code a few days ago including get_result() to receave the results from my database. Today I wantet to add to it and fix some errors. So I tried to use num_rows to see if anything were returned. But for this I had to use store_result() . And when I do this get_result() just returns a boolean of false. When I comment out store_result() everything works as it should. I know that the >= will mess it up. But I put the = there for debugging(to comment out the store_result() and see what

PHP Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement

人盡茶涼 提交于 2019-12-17 20:23:10
问题 Not sure why I'm getting this PHP warning message. It appears there are four parameters in the prepared statement, and also four variables in bind_param(). Thanks for any help! if($stmt = $mysqli -> prepare("SELECT url, month, year, cover_image FROM back_issues ORDER BY year DESC, month DESC")) { $stmt -> bind_param("ssis", $url, $month, $year, $cover_image); $stmt -> execute(); $stmt -> bind_result($url, $month, $year, $cover_image); $stmt -> fetch(); while ($stmt->fetch()) { echo "<li class

PDO: Passing extra parameters to a prepared statment than needed

百般思念 提交于 2019-12-17 20:20:53
问题 Can you send more parameters than needed to a prepared statement using PDO with no undesired side effects? That mights seem like a strange question but I ask because I have 4 queries in a row which all use similar and different parameters. The relevant parts of the queries: 1st (select, different table to others): WHERE threadID = :tid 2nd (select): WHERE user_ID = :u_ID AND thread_ID = :tid 3rd (update if 2nd was successful): SET time = :current_time WHERE user_ID = :u_ID AND thread_ID =

Dynamically change column name in PDO statement [duplicate]

心已入冬 提交于 2019-12-17 20:01:59
问题 This question already has an answer here : Can I use a PDO prepared statement to bind an identifier (a table or field name) or a syntax keyword? (1 answer) Closed 8 months ago . Is it possible pass a column name as parameter in a prepared MySQL statement? Take the following example: UPDATE Images SET :placement = :imageURL WHERE ID = :titleID; PDO adds ' around each parameter, so the middle line above becomes: SET 'Homepage' = '1.jpg' Which MySQL doesn't like. Is there a way to include

PHP PDO Prepared statement query not updating record

巧了我就是萌 提交于 2019-12-17 19:45:46
问题 I am having a problem using PHP's PDO object to prepare an update statement and updating the record. I have taken the raw SQL query and ran it in phpMyAdmin with the params replaced by their values that are passed to the function. Which updates the record as intended. However, when ran from the script it does not update. It throws zero errors and it returns an errorInfo() reply of 00000, which to my understanding is PDO's way of saying all is well. I know the PDO object works because it