prepared-statement

When to use prepared statements?

我们两清 提交于 2020-01-05 05:50:11
问题 I have few question. Spec: MySql database; server side language PHP 5.3.10 1) When should one use prepared statements? I am building a webapp which has users. I am retrieving/inserting data into the database constantly. I am currently not using prepared statements and I was wondering if that was wrong way of doing things? /** * Register a new user into the database. Please make sure to * hash the password. * @param type $fName First name of the user - String value. * @param type $lName Last

How can I set bit column to null?

半城伤御伤魂 提交于 2020-01-05 04:24:10
问题 The following only wants a primitive boolean (true or false). psmt.setBoolean(5, boolean) ; //wants primitive What if I want to set the bit to null? Sql server = [bit] NULL 回答1: You could use setNull preparedStatement.setNull(5, Types.BOOLEAN); 来源: https://stackoverflow.com/questions/26184937/how-can-i-set-bit-column-to-null

MySQL ConnectorJ with multiple SQL statements

不羁的心 提交于 2020-01-04 14:19:04
问题 Another developer tells me that there is a MySQL ConnectorJ option which can be turned on/off. This developer says that after turning this jdbc option to 'on', I can run a java jdbc query in the form: Connection jdbc = session.connection(); PreparedStatement pstmt = jdbc.prepareStatement("Update myTable set myField = 1 where myId = 1; Update myTable set anotherField = 2 where myId = 2"); pstmt.execute(); The idea behind running this prepared statement is that it runs two sql queries in a

PHP PDO Update prepared statement problem

坚强是说给别人听的谎言 提交于 2020-01-04 09:02:53
问题 Hi everyone I've been trying my hand at PDO recently, and am currently trying to write a basic database class for a project i'm working on. However i have ran into problems trying to write a function for carrying out an update query using prepared statements. function update($tabledata, $table, $where){ $fields = array_keys($tabledata); $data = array_values($tabledata); $fieldcount = count($fields); $wherefield = implode(array_keys($where)); $whereval = implode(array_values($where)); $this-

invalid object or resource mysqli_stmt

家住魔仙堡 提交于 2020-01-03 19:58:12
问题 I want to run multiple mysql queries( not concurrently). I am using prepared statements for doing so. This is a gist of my code : <?php if(isset($_GET['username'])&&isset($_GET['activationid'])){ require_once("../database/db_connect.php"); $stmt= $mysqli->stmt_init(); $stmt->prepare("Select username FROM users where username= ? AND activationid= ?"); $username=$_GET['username']; $activationid=$_GET['activationid']; $stmt->bind_param("ss",$username,$activationid); $stmt->execute(); $row=$stmt-

Inserting NULL value to a double data type MySQL Python

怎甘沉沦 提交于 2020-01-03 19:07:09
问题 I have a table. This is the create statement. CREATE TABLE `runsettings` ( `runnumber` mediumint(9) NOT NULL, `equipment` varchar(45) NOT NULL, `wafer` varchar(45) NOT NULL, `settingname` varchar(100) NOT NULL, `float8value` double DEFAULT NULL, `apcrunid` varchar(45) DEFAULT NULL, `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `intvalue` int(11) DEFAULT NULL, `floatvalue` float DEFAULT NULL, `Batch` varchar(45) DEFAULT NULL, `IndexNum` smallint(6) DEFAULT '1', `stringvalue` mediumtext,

Prepare and execute statements with ActiveRecord using PostgreSQL

佐手、 提交于 2020-01-03 13:04:04
问题 I am trying to insert values via a prepared statement using ActiveRecord. However, everytime I try: conn = ActiveRecord::Base.connection conn.prepare "SELECT * from sampletable where id = $1" conn.execute 3 After the second statement, I get: NoMethodError: undefined method `prepare' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter:0x000001027442c8> What should I do? I'm running Rails 3.2.1 and Ruby 1.9.2 UPDATE: I solved the problem. Thanks for the response, but it didn't work for

Prepare and execute statements with ActiveRecord using PostgreSQL

穿精又带淫゛_ 提交于 2020-01-03 13:01:37
问题 I am trying to insert values via a prepared statement using ActiveRecord. However, everytime I try: conn = ActiveRecord::Base.connection conn.prepare "SELECT * from sampletable where id = $1" conn.execute 3 After the second statement, I get: NoMethodError: undefined method `prepare' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter:0x000001027442c8> What should I do? I'm running Rails 3.2.1 and Ruby 1.9.2 UPDATE: I solved the problem. Thanks for the response, but it didn't work for

How to get scalar result from prepared statement?

守給你的承諾、 提交于 2020-01-03 08:42:18
问题 Is it possible to set the result from a prepared statement into a variable? I am trying to create the following stored procedure but it is failing: ERROR 1064 (42000) at line 31: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'stmt USING @m, @c, @a; DROP PROCEDURE IF EXISTS deleteAction; DELIMITER $$ CREATE PROCEDURE deleteAction( IN modul CHAR(64), IN controller CHAR(64), IN actn CHAR(64)) MODIFIES SQL

PreparedStatement.setString() method without quotes [duplicate]

喜欢而已 提交于 2020-01-03 07:20:11
问题 This question already has answers here : Using Prepared Statements to set Table Name (7 answers) Closed 6 years ago . I'm trying to use a PreparedStatement with code similar to this: SELECT * FROM ? WHERE name = ? Obviously, what happens when I use setString() to set the table and name field is this: SELECT * FROM 'my_table' WHERE name = 'whatever' and the query doesn't work. Is there a way to set the String without quotes so the line looks like this: SELECT * FROM my_table WHERE name =