prepared-statement

Mysql query to Mysqli and Prepare Statement

余生长醉 提交于 2019-12-11 14:35:43
问题 I am trying to convert my old queries to mysqli + prepare statement but I could use some help. My old loop looks something like this: $query = "SELECT * FROM `table`;"; $result = @mysql_query($query); if (@mysql_num_rows($result) > 0) { for ($i=0; $i < @mysql_num_rows($result); $i++) { $row = @mysql_fetch_array($result); print $row['id']; print " - "; print $row['username']; print "<br>"; } } But I am stuck with the mysqli + prepare statement.. Thanks! 回答1: $stmt = $mysqli->prepare("SELECT *

Converting from mysqli to prepared statements [duplicate]

戏子无情 提交于 2019-12-11 14:09:45
问题 This question already has answers here : When to use single quotes, double quotes, and backticks in MySQL (12 answers) Closed 5 months ago . I am attempting to convert code from the mysqli_* statements to prepared statements to prevent SQL injection. The following code is what I am attempting to convert (and it currently works correctly): $details = mysqli_query($linkDB,"SELECT * FROM ".PREFIX."Issues WHERE id='".$_POST['article']."' AND disabled='0' LIMIT 1"); $detail = mysqli_fetch_assoc(

mysqli prepared statement cannot read unicode

懵懂的女人 提交于 2019-12-11 14:00:39
问题 Assume Adams’ Inn America’s Best Inn stored in the db table establishment I have to check Adams’ Inn America’s Best Inn in a variable $EstablishmentName $stmt = $sql->prepare("SELECT ID FROM `establishment` WHERE Name=? LIMIT 1"); $stmt->bind_param("s",$EstablishmentName); $stmt->execute(); $stmt->store_result(); print $stmt->num_rows; The problem is I can't find them. OUTPUT 0 Note enclosed $EstablishmentName with mb_convert_string($EstablishmentName,'HTML-ENTITIES') else you'll end up with

How to create new MySQL database user with MySQLi prepared statements?

余生颓废 提交于 2019-12-11 12:40:31
问题 I'm trying to add new database user by these statements: $insert = $db->prepare("CREATE USER ? IDENTIFIED BY ?"); $insert->bind_param('ss', $_POST['username'], $_POST['pass']); $insert->execute(); Database gives me error: You have an error in your SQL syntax; (...) near '? IDENTIFIED BY ?' at line 1 When I try to add new user without ? wildcards, everything is fine: CREATE USER john IDENTIFIED BY 'johnpassword' //this works , but even using CONCAT("'", ?, "'") for submitting data doesn't help

Mockito UnfinishedStubbingException with when().thenReturn()

眉间皱痕 提交于 2019-12-11 12:39:28
问题 I am getting the error message Unfinished Stubbing detected here , when running the following code: import static org.mockito.Mockito.mock; import static org.mockito.Mockito.*; import org.mockito.Mock; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; @RunWith(PowerMockRunner.class) public class PatchWriterTaskTest { @Before public void

Java - Prepared statements and arrays

旧城冷巷雨未停 提交于 2019-12-11 12:31:51
问题 How can I handle an array in a prepared statement? i.e, I want to do a query and one of the parameters I get is an array of strings which I want to use in the query (Don't select rows that have a field that's in the array)? 回答1: Some JDBC drivers may already (before JDBC 4) contain proprietary extensions that support array-type parameters in prepared statements - you would need to consult with API for this. This would mean that you have to use and manipulate array-like type in SQL. One work

How to insert many records to MySQL faster,Java?

梦想的初衷 提交于 2019-12-11 12:26:39
问题 I am making a web service in which number of records are coming and they have to be inserted in database faster. I use PreparedStatement . Are there any ways to insert records faster? The data is coming dynamically so, how much data is coming to insert could not be hard-coded. I have a different class which is common for database queries and I am calling it through my 'Servlet'. Here is the database query code: public void insertUser_Details(String name,String address) throws Exception { ps

Fatal error: Call to a member function prepare() on a non-object with PDO

南笙酒味 提交于 2019-12-11 11:31:35
问题 I have a file that includes another file: index.php is a dynamic template <?php $db = new PDO("mysql:host=localhost;dbname=db", $DB_USER, $DB_PASSWORD); include(functions.php); ?> functions.php <?php $preparedStatement = $db->prepare("SELECT id FROM table LIMIT 1"); $preparedStatement->execute(); $firstId = $preparedStatement->fetchAll(); ?> when functions.php executes I get: Fatal error: Call to a member function prepare() on a non-object at line $preparedStatement = $db->prepare("SELECT id

Results, such as RETURNING, from uncomitted execs?

笑着哭i 提交于 2019-12-11 11:05:12
问题 With libpqxx, is it possible for one prepared statement that exec s but has not yet been commit ted to store results in a result for use in later prepared statements? If so, how can this be done? Code I've stripped it down for readability, but this is essentially what I'm trying to do: void prepare_write_parent_table(connection_base &c){ try { c.prepare("write_parent_table", "INSERT INTO parent_table (column_1) " "SELECT $1 " "RETURNING id" ) ("character", pqxx::prepare::treat_string); }

Prepared statements for Lua with LuaSQL

北城余情 提交于 2019-12-11 10:55:35
问题 There is little documentation on prepared statements in luaSQL. So i tried to put together some code to use prepared statements in LuaSQL. Unfortunately it's not working. (I'm using a mysql database) luasql = require "luasql.mysql" env = assert (luasql.mysql()) con = assert (env:connect("database","user","password","localhost")) name = "insert_sql_injection_code_here" query= "INSERT INTO `table`(`text`) VALUES ('"..name.."')" cur = assert (con:execute(query)) -- As you can see, query is