prepared-statement

PHP/PDO: use simple prepared statement with query return/affected rows?

你离开我真会死。 提交于 2019-12-07 09:40:09
问题 I am new to PDO objects and cannot find a single piece of documentation that will help me. Say I got a simple code to delete a row: $count = $dbh->exec("DELETE FROM fruit WHERE colour = 'red'"); That will return affected rows, but how would I use prepared statements with that? Can use use $dbh->prepare AND $dbh->exec or query !? 回答1: It should be the same as any other statement: $stmt = $dbh->prepare("DELETE FROM fruit WHERE colour = ?"); $stmt->execute(array('red')); $count = $stmt->rowCount

PHP PDO SQLite prepared statement issues

帅比萌擦擦* 提交于 2019-12-07 09:05:49
问题 I am trying to migrate a PHP app from MySQL to SQLite, and some things that used to work, simply stopped working now. I am using PDO through a custom database wrapper class (the class is a singleton, seems logical to do it like that). The problem: When trying to execute a query on a prepared statement, it throws a "fatal error: Call to a member function execute() on a non-object ...". Relevant code (narrowed it down to this, after some hours of var_dumps and try-catch): Connection string:

PHP ::: Prepared Statements ::: freeresult() ::: close()

巧了我就是萌 提交于 2019-12-07 06:36:44
问题 What is the importance of using: $stmt->free_result(); $stmt->close(); After a database call using prepared statments like this: $mysqli=new mysqli("database", "db", "pass", "user"); $stmt = $mysqli->prepare("SELECT email FROM users WHERE id=? "); $stmt->bind_param('i',$_SESSION['id']); $stmt->execute(); $stmt->bind_result($email); while($stmt->fetch()){ echo $email; } $stmt->free_result(); //why do i need this? $stmt->close(); //why do i need this? Im asking because I do not see any

MySQLi prepared statement returning false

大兔子大兔子 提交于 2019-12-07 06:11:19
问题 I'm trying to run multiple queries on my database using MySQLi. This is my code: $stmt = $mysqli->prepare('SELECT password FROM `users` WHERE username=? LIMIT 1'); $stmt->bind_param('s', $username); $stmt->execute(); $stmt->bind_result($hashedPass); $stmt->fetch(); /* Check the passwords match */ $pwdHasher = new PasswordHash(8, FALSE); if(!$pwdHasher->CheckPassword($password, $hashedPass)) exit; $stmt = $mysqli->prepare('SELECT u_id FROM `users` WHERE username=? LIMIT 1'); $stmt->bind_param(

updating records with prepared statements, checking if update worked

流过昼夜 提交于 2019-12-07 04:46:54
问题 I have a query that updates a record on my database, it works fine but i wanted to know how to check if the update has happened so i can return true and display the right message? Now i know with a SELECT query i can do: if(stmt->fetch()) If that is true i return true and saying "records found" but i haven't got a clue how to do it for an update query? Anyone know how to? $query = "UPDATE user SET password = ? WHERE email = ?"; if($stmt = $conn->prepare($query)) { $stmt->bind_param('ss', $pwd

Prepared Statements and JDBC Drivers

我与影子孤独终老i 提交于 2019-12-07 03:34:13
问题 I have the below questions on Prepared Statements in Java. Is it beneficial to use Prepared Statements when the SQL Query does not have any Where clause ? Assume a simple query Select * from tablename; It is said that the Prepared Statement is compiled once and only the values are substituted the second time. Hence it is faster as the Query validation and compilation step can be skipped. Where is the compiled form stored ? What is the life time of this compiled form ? 回答1: A PreparedStatement

Oracle JDBC performance of ResultSet

我的未来我决定 提交于 2019-12-07 03:16:55
问题 I was using so far something like this for querying my database that was working perfectly fine : PreparedStatement prepStmt = dbCon.prepareStatement(mySql); ResultSet rs = prepStmt.executeQuery(); But then I needed to use the rs.first(); in order to be able to iterate over my rs multiple times. So I use now PreparedStatement prepStmt = dbCon.prepareStatement(mySql,ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); My question is related to the performance of the two. What do I

How to prepare statements and bind parameters in Postgresql for C++

孤街浪徒 提交于 2019-12-07 02:33:59
问题 I'm quite new to C++ and know a little bit about pqxx library. What I want to implement is to prepare statements and bind parameters. In PHP I'm used to doing this in such a nice and concise manner: $s = $db->prepare("SELECT id FROM mytable WHERE id = :id"); $s->bindParam(':id', $id); $s->execute(); or using tokens: $data = array(); $data[] = 1; $data[] = 2; $s = $db->prepare("SELECT id FROM mytable WHERE id = ? or id = ?"); $s->execute($data); I tried to fugure out from pqxx documentation

pg_query_params return error: bind message supplies 2 parameters, but prepared statement “” requires 1

▼魔方 西西 提交于 2019-12-06 20:18:51
问题 $Query = pg_query_params($db, 'SELECT username FROM users WHERE id = $1 AND password=(crypt(\'$2\',password)) LIMIT 1', array(33,'thepassword')); "bind message supplies 2 parameters, but prepared statement "" requires 1" The problem seem around the '$2' parameter, heredoc string doesnt works. Suggestions ? 回答1: Single quotes are used in SQL for string literals. That means that this: '$2' is just a string that contains the characters $ and 2 rather than a placeholder. If you want a placeholder

Prepared Statement and Statement/Query Caching

空扰寡人 提交于 2019-12-06 17:05:47
问题 I am trying to understanding if Statement caching is useful in case of parametrized prepared statements. As per my understanding If I use caching, then query will cached based on its 'String'. In this case, if a query has different values of parameter then it is a different / new statement/string w.r.t. caching. Also, when parameters change, the results also change. Since prepared statements are parameterized, is it really useful to use caching in this case. I am using JDBC/Snaq DB Pool/