prepared-statement

Are Dynamic Prepared Statements Bad? (with php + mysqli)

流过昼夜 提交于 2019-12-17 18:24:51
问题 I like the flexibility of Dynamic SQL and I like the security + improved performance of Prepared Statements. So what I really want is Dynamic Prepared Statements, which is troublesome to make because bind_param and bind_result accept "fixed" number of arguments. So I made use of an eval() statement to get around this problem. But I get the feeling this is a bad idea. Here's example code of what I mean // array of WHERE conditions $param = array('customer_id'=>1, 'qty'=>'2'); $stmt = $mysqli-

AddWithValue without DBType causing queries to run slowly

故事扮演 提交于 2019-12-17 17:11:30
问题 I've been using cmd.Parameters.AddWithValue, and not specifying a DBType (int, varchar,...) to run queries. After looking at SQL Profiler, it seems that queries run with this method run a lot slower than when you specify the data type. To give you an idea of how much slower it is, here's an example. The query is a simple lookup on a single table, and the column in the where statement is indexed. When specifying the data type, a certain query runs in about 0 MS (too small for sql server to

ODBC prepared statements in PHP

不想你离开。 提交于 2019-12-17 16:06:14
问题 I'm trying to use odbc_prepare and odbc_execute in PHP as follows: $pstmt=odbc_prepare($odb_con,"select * from configured where param_name='?'"); $res=odbc_execute($pstmt,array('version')); var_dump($res); //bool(true) $row = odbc_fetch_array($pstmt); var_dump($row); //bool(false) The first var_dump returns true so the execute succeeds, but there is no row returned. A row does indeed exist with the param_name = 'version'. Why is no row returned? To make things interesting, I ran another very

Two different prepared statements in one single batch

℡╲_俬逩灬. 提交于 2019-12-17 15:44:40
问题 I want to send two different prepared statements in one single batch . Currently I am doing this in two as you can see in the commented lines and it works, but that is not the main objective here. Can anyone tell me what to put in place of those comments to get this thing to work? import java.lang.ClassNotFoundException; import java.math.BigDecimal; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.DriverManager; public class Main {

How to insert into MySQLusing a prepared statement with PHP [duplicate]

久未见 提交于 2019-12-17 10:54:06
问题 This question already has answers here : How can I prevent SQL injection in PHP? (28 answers) Closed 6 years ago . I am just learning about databases and I want to be able to store user inputs. What would be a basic example on how to get form data and save it to a database using PHP? Also making the form secure from SQL attacks. 回答1: File sample.html <form action="sample.php" method="POST"> <input name="sample" type="text"> <input name="submit" type="submit" value="Submit"> </form> File

How to run the bind_param() statement in PHP?

时间秒杀一切 提交于 2019-12-17 09:50:22
问题 I'm trying to make the following code work but I can't reach the execute() line. $mysqli = $this->ConnectLowPrivileges(); echo 'Connected<br>'; $stmt = $mysqli->prepare("SELECT `name`, `lastname` FROM `tblStudents` WHERE `idStudent`=?"); echo 'Prepared and binding parameters<br>'; $stmt->bind_param('i', 2 ); echo 'Ready to execute<br>' if ($stmt->execute()){ echo 'Executing..'; } } else { echo 'Error executing!'; } mysqli_close($mysqli); The output that I get is: Connected Prepared and

PreparedStatements and performance

﹥>﹥吖頭↗ 提交于 2019-12-17 09:43:09
问题 So I keep hearing that PreparedStatements are good for performance. We have a Java application in which we use the regular 'Statement' more than we use the 'PreparedStatement'. While trying to move towards using more PreparedStatements, I am trying to get a more thorough understanding of how PreparedStatements work - on the client side and the server side. So if we have some typical CRUD operations and update an object repeatedly in the application, does it help to use a PS? I understand that

using nulls in a mysqli prepared statement

时光总嘲笑我的痴心妄想 提交于 2019-12-17 06:51:45
问题 In a mysqli prepared statement, a NULL gets turned into '' (in the case of a string) or 0 (in the case of an integer). I would like to store it as a true NULL. Is there any way of doing this? 回答1: I know this is an old thread, but it's possible to bind a true NULL value to the prepared statements (read this). You can, in fact, use mysqli_bind_parameter to pass a NULL value to the database. simply create a variable and store the NULL value (see the manpage for it) to the variable and bind that

What does a question mark represent in SQL queries? [duplicate]

人盡茶涼 提交于 2019-12-17 06:35:11
问题 This question already has answers here : What is the question mark's significance in MySQL at “WHERE column = ?”? (4 answers) Closed 5 years ago . While going through some SQL books I found that examples tend to use question marks ( ? ) in their queries. What does it represent? 回答1: What you are seeing is a parameterized query . They are frequently used when executing dynamic SQL from a program. For example, instead of writing this ( note: pseudocode ): ODBCCommand cmd = new ODBCCommand(

How to prepare statement for update query?

故事扮演 提交于 2019-12-17 06:14:08
问题 I have a mysqli query with the following code: $db_usag->query("UPDATE Applicant SET phone_number ='$phone_number', street_name='$street_name', city='$city', county='$county', zip_code='$zip_code', day_date='$day_date', month_date='$month_date', year_date='$year_date' WHERE account_id='$account_id'"); However all the data is extracted from HTML documents so to avoid errors I would like to use a prepared statement. I found PHP documentation on bind_param() but there is no UPDATE example. 回答1: