prepared-statement

UPDATE query with prepared statements

北城余情 提交于 2020-01-06 09:01:10
问题 Having problems with and update query i keep getting Warning: Crud::update() [crud.update]: Property access is not allowed yet in crud.php on line 60 This is my code $stmt = $this->mysql->prepare('UPDATE links SET title = ?, url = ?, comment = ? WHERE id = ?'); $stmt->bind_param('sssi',$title,$url,$comment,$id); $stmt->execute(); $stmt->close(); on line 60 return $stmt->affected_rows; Googled it and only found one reference in the php documentation in a comment but i couldn't understand the

Prepared statements while fetching prepared statement

送分小仙女□ 提交于 2020-01-06 07:55:31
问题 I want to make a loop with one INSERT query for each fetched row from a previous query with prepared statements. In a more visual way: MAKE QUERY While Fetching - Make new query I can't close my statement since I need it to keep working... The problem is that when we use prepared statements, we have to fetch all data before doing a new prepare(). So, how could I do this? Maybe without statements, but it's not a nice solution. 回答1: You are going to kill your DB (and if you have a DBA your DBA

How to use prepared statements in this query?

纵然是瞬间 提交于 2020-01-05 13:13:06
问题 I'm new to PHP and PDO, and I try to use prepared statements here. After 1 hour of trying around I give up. Or my tutorial was just horribly bad. EDIT: This works perfectly without prepared statements: try { $dbh = new PDO('mysql:host=localhost;dbname=test', 'root', 'root'); $prepared = $dbh->prepare('SELECT * from sys_navigation_point WHERE name="root"'); //$prepared->bindParam('foo', 'root'); $prepared->execute(); foreach($prepared as $row) { print_r($row); } $dbh = null; } catch

Prepared Statements IN Clause Java Microsoft JDBC

家住魔仙堡 提交于 2020-01-05 12:57:34
问题 I've seen examples here and elsewhere that say this should work. With '1' parameter in the IN CLAUSE I have success: SELECT AVG( ( High_Temperature + Low_Temperature ) / 2.0 ) FROM obs_masterAll WHERE Observation_Valid_Time = ? AND Location_ID IN ( ? ); Microsoft JDBC Driver 4.2 for SQL Server 4.2.6420.100 Parameter Count = 2 2010, 36.5 But, with more than one parameter in the IN CLAUSE, I get this: SELECT AVG( ( High_Temperature + Low_Temperature ) / 2.0 ) FROM obs_masterAll WHERE

JDBC PreparedStatement and parameters (?) in select query [duplicate]

旧时模样 提交于 2020-01-05 12:57:12
问题 This question already has answers here : Variable column names using prepared statements (6 answers) Closed 2 years ago . I have a connection with oracle database like this: String selectSQL = "SELECT ?,supplier_name FROM supplier WHERE supplier_id = ?"; PreparedStatement preparedStatement = con.prepareStatement(selectSQL); preparedStatement.setString(1, "supplier_id"); preparedStatement.setInt(2, 1); ResultSet rs2 = preparedStatement.executeQuery(); while (rs2.next()) { String userid = rs2

PHP: Injection protection using prepared statements

让人想犯罪 __ 提交于 2020-01-05 11:02:36
问题 I am familiar with using PHP to perform mySQL queries. However, I have been using reg exps as protection against injection attacks. After reading several questions/answers here on SO, I've decided to opt for prepared statements instead. There's two options available (let me know if there are more): mysqli prepared statements PDO prepared staments Question 1 I am trying to understand the code examples given on the linked pages. For mysqli , Example #1 : if ($stmt = $mysqli->prepare("SELECT

PHP: Injection protection using prepared statements

别等时光非礼了梦想. 提交于 2020-01-05 11:02:20
问题 I am familiar with using PHP to perform mySQL queries. However, I have been using reg exps as protection against injection attacks. After reading several questions/answers here on SO, I've decided to opt for prepared statements instead. There's two options available (let me know if there are more): mysqli prepared statements PDO prepared staments Question 1 I am trying to understand the code examples given on the linked pages. For mysqli , Example #1 : if ($stmt = $mysqli->prepare("SELECT

PHP PDO prepared statement IN() array [duplicate]

霸气de小男生 提交于 2020-01-05 08:43:09
问题 This question already has answers here : PDO binding values for MySQL IN statement (8 answers) PHP - Using PDO with IN clause array (7 answers) Closed 5 years ago . From the PHP Manual : You cannot bind multiple values to a single named parameter in, for example, the IN() clause of an SQL statement. But can you use multiple values using question mark parameter markers? Or do you have to prepare() a new statement every time the number of values changes? SELECT * FROM `table` WHERE `column` IN(

Mysqli insert id: $mysqli->insert_id; or $ID_user=$stmt->insert_id?

旧巷老猫 提交于 2020-01-05 05:52:26
问题 which one is the correct code in a prepared statement? $ID_user=$mysqli->insert_id; or $ID_user=$stmt->insert_id; ? $stmt = $mysqli->prepare("INSERT INTO users (first_name, last_name) VALUES (? ,?)"); $stmt->bind_param("ss",$first_name,$last_name); if($stmt->execute()) { $ID_user=$mysqli->insert_id; // or $ID_user=$stmt->insert_id; } 回答1: There is absolutely no difference, you can use whatever you wish. 来源: https://stackoverflow.com/questions/43184732/mysqli-insert-id-mysqli-insert-id-or-id

Mysqli insert id: $mysqli->insert_id; or $ID_user=$stmt->insert_id?

社会主义新天地 提交于 2020-01-05 05:52:08
问题 which one is the correct code in a prepared statement? $ID_user=$mysqli->insert_id; or $ID_user=$stmt->insert_id; ? $stmt = $mysqli->prepare("INSERT INTO users (first_name, last_name) VALUES (? ,?)"); $stmt->bind_param("ss",$first_name,$last_name); if($stmt->execute()) { $ID_user=$mysqli->insert_id; // or $ID_user=$stmt->insert_id; } 回答1: There is absolutely no difference, you can use whatever you wish. 来源: https://stackoverflow.com/questions/43184732/mysqli-insert-id-mysqli-insert-id-or-id