prepared-statement

JAVA JDBC mySql Prepared statement Update query [duplicate]

柔情痞子 提交于 2021-02-05 07:45:27
问题 This question already has answers here : MySQLSyntaxErrorException near “?” when trying to execute PreparedStatement (2 answers) Closed 1 year ago . I am trying to execute the following code package jdbclesson; import java.sql.*; public class PreparedQuery { public static void main(String[] args) throws Exception { String url = "jdbc:mysql://localhost:3306/alien?useSSL=false"; String uname = "root"; String pass = "ma123"; String query = "UPDATE student SET username= ? where userid= ? ";

JAVA JDBC mySql Prepared statement Update query [duplicate]

杀马特。学长 韩版系。学妹 提交于 2021-02-05 07:45:06
问题 This question already has answers here : MySQLSyntaxErrorException near “?” when trying to execute PreparedStatement (2 answers) Closed 1 year ago . I am trying to execute the following code package jdbclesson; import java.sql.*; public class PreparedQuery { public static void main(String[] args) throws Exception { String url = "jdbc:mysql://localhost:3306/alien?useSSL=false"; String uname = "root"; String pass = "ma123"; String query = "UPDATE student SET username= ? where userid= ? ";

Insert BIT value in MySQL using PDO Prepared Statement

眉间皱痕 提交于 2021-02-05 04:55:47
问题 How do I insert a BIT value in MySQL using a PDO Prepared Statement? Below is what I tried and my results. <?php function testIt($value) { $sql='INSERT INTO test(id,data) VALUES(?,?)'; $stmt=db::db()->prepare($sql); $stmt->execute(array(0,$value)); $id=db::db()->lastInsertId(); $sql='SELECT * FROM test WHERE id='.$id; $stmt=db::db()->query($sql); $rs=$stmt->fetch(PDO::FETCH_ASSOC); echo("Test for {$value} returns id {$rs['id']} and data {$rs['data']}<br>"); } date_default_timezone_set(

Insert BIT value in MySQL using PDO Prepared Statement

ε祈祈猫儿з 提交于 2021-02-05 04:54:59
问题 How do I insert a BIT value in MySQL using a PDO Prepared Statement? Below is what I tried and my results. <?php function testIt($value) { $sql='INSERT INTO test(id,data) VALUES(?,?)'; $stmt=db::db()->prepare($sql); $stmt->execute(array(0,$value)); $id=db::db()->lastInsertId(); $sql='SELECT * FROM test WHERE id='.$id; $stmt=db::db()->query($sql); $rs=$stmt->fetch(PDO::FETCH_ASSOC); echo("Test for {$value} returns id {$rs['id']} and data {$rs['data']}<br>"); } date_default_timezone_set(

Is it possible to combine mysqli prepared statement with multiple inserts?

一笑奈何 提交于 2021-02-04 06:13:38
问题 I am well-versed in the old php mysql extension. I am working on my first script that uses the mysqli extension. I am going to be inserting a large number of rows into a table that are being generated dynamically. Is it possible to use a prepared statement to insert multiple rows into a table without previously knowing the number of new rows that will be inserted each time? $stmt = $mysqli->prepare("INSERT INTO `activity` (`id`, `name`, `type`) VALUES ?, ?, ?;"); If that isn't possible, which

PHP pg_prepare() table name as parameter

走远了吗. 提交于 2021-02-02 09:32:44
问题 I'm trying to convert this query from a normal pg_query() to pg_prepare() & pg_execute() . Its a generic query that I reuse when I need to update different tables from different pages in order to keep my code clean. I've just realised that parameters can be used only in where clauses and not in other parts of the query. $res = pg_query($con, "update " . $_REQUEST['table'] . " set " . $_REQUEST['colname'] . "=" . $colval . " where " . $_REQUEST['colnameid'] . "=" . $_REQUEST['colvalid'] . "

MySQL 5.7 prepared statements updating the wrong timestamp column

Deadly 提交于 2021-01-29 06:30:40
问题 I'm having some issues with an update on table, when used with a prepared statement. Seems like mysql is updateing a wrong column which was not even specifed in the update command. prepare: drop table test1; create table test1( id int not null, show_from timestamp not null, updated_at timestamp NULL DEFAULT NULL ); insert into test1(id, show_from, updated_at) values(1, '2018-01-11 12:10:11.19808', '2019-04-15 11:50:00.704748'); do this in one batch: UPDATE test1 SET show_from='2018-04-15 11

MySQL 5.7 prepared statements updating the wrong timestamp column

会有一股神秘感。 提交于 2021-01-29 06:25:28
问题 I'm having some issues with an update on table, when used with a prepared statement. Seems like mysql is updateing a wrong column which was not even specifed in the update command. prepare: drop table test1; create table test1( id int not null, show_from timestamp not null, updated_at timestamp NULL DEFAULT NULL ); insert into test1(id, show_from, updated_at) values(1, '2018-01-11 12:10:11.19808', '2019-04-15 11:50:00.704748'); do this in one batch: UPDATE test1 SET show_from='2018-04-15 11

using prepared mysqli statements to bind parameters into the SELECT section of a query

橙三吉。 提交于 2021-01-28 00:39:11
问题 I am building a web app that imports data from data feeds in php/mysql. I import the data into a buffer/temp holding table. As each data format is different I choose the column to select based on the particular source. I am having trouble getting this query to work in this context : $stmt = $this->dbObj->prepare("SELECT mk.PK_phone_maker, b.?, b.phoneDescription b.thumbPic, FROM buffer_table b left join mobile_phone pm on b.? = pm.phoneModel LEFT JOIN phone_maker mk on mk.CompanyName = b.?

How to use prepare statements / bind values in a query in Joomla 3?

此生再无相见时 提交于 2021-01-27 14:13:57
问题 I'd like to know how to bind values in where clause. I have understood that is something that MUST be done for security reasons. $db = JFactory::getDbo(); $query = $db->getQuery(true); $query ->select("*") ->from($db->quoteName("food")) ->where("taste = :taste") ->bind(':taste', 'sweet'); $db->setQuery($query); $rows = $db->loadAssocList(); I'm getting this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use