prepared-statement

Syntax for “RETURNING” clause in Mysql PDO

我与影子孤独终老i 提交于 2019-12-23 15:41:12
问题 I'm trying to add a record, and at the same time return the id of that record added. I read it's possible to do it with a RETURNING clause. $stmt->prepare("INSERT INTO tablename (field1, field2) VALUES (:value1, :value2) RETURNING id"); but the insertion fails when I add RETURNING. There is an auto-incremented field called id in the table being added to. Can someone see anything wrong with my syntax? or maybe PDO does not support RETURNING ? 回答1: I don't think it has anything to do with PDO

prepared statements using psycopg

对着背影说爱祢 提交于 2019-12-23 15:09:13
问题 I'm a beginner at python. We use this code to execute SQL commands. cur.execute("INSERT INTO test (num, data) VALUES (%s, %s)", (100, "abcdef")) I wonder is this prepared statement or just a client side quoting? 回答1: No, it does not, not for psycopg2 at least. The "Prepare" in the docs refers to a "PREPARE TRANSACTION" which is entirely different than a prepared statement. You can emulate a prepared statement, by overriding the methods or executing extra statements, however. See: An example

Using one parameter multiple times in prepared mysqli-statement

梦想与她 提交于 2019-12-23 13:43:04
问题 Is it possible to use one parameter in a prepared mysqli -statement multiple times with only binding it one time ? something like this $stmt = $mysqli->prepare(SELECT * FROM user WHERE age BETWEEN ?1 - 2 AND ?1 + 2); $stmt->bind_param('i', $myAge); I think this is possible with PDO , but I don't konw how to do this with mysqli . 回答1: Just to close the question: The answer is no . If you want to bind a parameter only one time and using it multiple times in a query you have to use PDO and this

mysqli, prepared statements, and INSERT-SELECTs

末鹿安然 提交于 2019-12-23 13:13:25
问题 Let's pretend that I have two tables in an InnoDB database: categories and jokes ; and that I'm using PHP/MySQLi to do the work. The tables look like so: CATEGORIES id (int, primary, auto_inc) | category_name (varchar[64]) ============================================================ 1 knock, knock JOKES id (int, primary, auto_inc) | category_id (int) | joke_text (varchar[255]) ============================================================================= empty Thanks to a previous answer on

Changed PDO::ATTR_EMULATE_PREPARES to FALSE and getting “Invalid parameter number” error

 ̄綄美尐妖づ 提交于 2019-12-23 09:58:36
问题 I have the following code forexample: $dbStatement=$this->dbObject->prepare("SELECT AVG(quality) as quality, AVG(adequacy) as adequacy, AVG(friendliness) as friendliness, SUM(overall) as overall, SUM(completed) as completed, type FROM (SELECT AVG(quality) as quality, AVG(adequacy) as adequacy, AVG(friendliness) as friendliness, COUNT(id) as overall, SUM(is_completed) as completed, category_id, type FROM valuation a WHERE status =1 AND type =:01 AND ((type='employer' AND owner_id=:02) OR (type

SQL Prepared Statement to Create Table

心不动则不痛 提交于 2019-12-23 08:01:43
问题 I wanted to know of some way to create table on the fly based on user input(SQL Prepared Statement) CREATE TABLE ? ( First_Name char(50), Last_Name char(50) ) What should i put in place of question mark 回答1: PreparedStatement placeholders are not intended for table names nor column names, they are only intended for actual column values. So you would have to create the (prepared) statement string dynamically, which means your application will be vulnerable to SQL injection . Depending on how

Why cant you pass MYSQL functions into prepared PDO statements?

荒凉一梦 提交于 2019-12-23 07:30:05
问题 In my mind, the following script should work: $stmt = $db->prepare("UPDATE table SET status = ?, date_modified = ?"); $stmt->execute(array(1, 'NOW()')); but when passing NOW() into the prepared statement, nothing happens. Replacing NOW() with an actual date (i.e. 2010-11-23) works just fine. I am unable to find explanation online. Any ideas? EDIT Just to further clarify and rid of any confusion in the question, I want to actually pass a variable into the prepared statement HOWEVER, the

“Property access is not allowed yet” warning when using prepared statement

前提是你 提交于 2019-12-23 07:27:01
问题 I'm trying to make a log in system by using AES_ENCRYPT() to encode my password. But I have some warning from xdebug when trying to implement these codes: ... $key = 'd0gis=SUPER-cute'; $sql = "SELECT * FROM `users2` WHERE username = ? AND pwd = AES_ENCRYPT(?, ?)"; $stmt = $conn->stmt_init(); $stmt->prepare($sql); $stmt->bind_param('sss', $username, $password, $key); $stmt->execute(); $stmt->store_result(); ... When the debugger meets line 8 or $stmt->prepare($sql); , 6 same warning tables

dynamic prepared insert statement

南笙酒味 提交于 2019-12-23 05:29:12
问题 Let me preface that I just started learning prepared statements so much of this might just be to much to grasp, but I want to try. I am trying to make a dynamic create function within my DatabaseObject class. The function would take any number of values of potentially any number of the different allowed data types. Unfortunately nothing I have tried has worked. Here is the code. public function create() { $db = Database::getInstance(); $mysqli = $db->getConnection(); //array of escaped values

How to create a prepared statement dynamically - and re-use the query

主宰稳场 提交于 2019-12-23 05:19:16
问题 I've been trying to create a class that handles queries from different Classes that create different objects, for example. Class Employees, Class Customers, Class Sales I'd like to pass a SQL query via the constructor derived from JTextField values (to the query class, "Database"). For example, from two different classes: new Database (SELECT PRODUCT FROM SALES WHERE DATE = YESTERDAY); new Database (SELECT FULLNAMES FROM CUSTOMER WHERE ADDRESS = NEWYORK); The problem I'm facing is when it