prepared-statement

how can i set a special date in PreparedStatement parameters?

痴心易碎 提交于 2019-12-25 18:18:50
问题 heloo... I have a problem when I want to use date in my code I have a class that named ReportService and in this class I use jdbc to connect my database and after that I want to get a report from my database in a special date.frist I write this : ("select sum(cost) from mem_income where trunc(date_out) = to_date ('31-jul-2013' , 'dd-mm-yyyy')"); and this work good.but after that I want to pass my date from my main class: PreparedStatement pst = conn.prepareStatement("select sum(cost) from mem

PHP unable to retrieve data from database [duplicate]

≯℡__Kan透↙ 提交于 2019-12-25 17:04:16
问题 This question already has answers here : How can I prevent SQL injection in PHP? (28 answers) mysqli_fetch_assoc() expects parameter / Call to a member function bind_param() errors. How to get the actual mysql error and fix it? (1 answer) Reference - What does this error mean in PHP? (35 answers) Closed 2 days ago . I'm new to PHP and I'm trying to authenticate the users by their username and password.(basically login form) If their password matches then they are redirected to welcome.php . I

PHP -> PDO -> Prepare -> Call Procedure -> Insert Into -> Bind Parameters

和自甴很熟 提交于 2019-12-25 09:58:18
问题 using this procedure CREATE PROCEDURE `Insert_New_Return_Id`(IN Insert_Stmnt varchar(1000), OUT IDNum int) BEGIN SET @buffer = Insert_Stmnt; PREPARE stmt FROM @buffer; EXECUTE stmt; SELECT LAST_INSERT_ID() INTO IDNum; DEALLOCATE PREPARE stmt; END the following code works fine : $statement=$con->prepare("CALL Insert_New_Return_Id (\"INSERT INTO users (first_name,last_name)VALUES('test','test')\",@ID)"); $statement->execute(); $statement=$con->query("SELECT @ID"); while ($row = $statement-

How to bind values to bound statement in a generic way using datastax java driver?

孤街醉人 提交于 2019-12-25 08:38:05
问题 I am working with Datastax Java driver to read and write data into Cassandra. I am using datastax java driver 3.1.0 and my cassandra cluster version is 2.0.10. I have created below two methods to execute my cql query. I am calling first method when I don't need to set any value in my cql query so it works for cql string like below: select * from testkeyspace.testtable where row_id=1 // cql-1 select * from testkeyspace.meta where row_id=1 // cql-2 select * from testkeyspace.proc where row_id=1

fetching user data with prepared statement

瘦欲@ 提交于 2019-12-25 07:59:36
问题 hey guy so am trying to create profile table by displaying user data. have used some code samples that you'll see in the code below, have commented some out so watch out. here is my code // $stmt = $con->prepare("SELECT * FROM user WHERE id = ? "); // $stmt->bind_param('s', $id); // if($stmt->execute()){ // //$result = $stmt->get_result(); // if($result->num_rows > 0){ // // username exists // //$stmt->bind_result($firstname, $lastname, $user_type, $email, $profession); // echo 'No Data Found

mysqli - handling errors with transactions

假如想象 提交于 2019-12-25 07:48:23
问题 How to properly handle errors with transactions and prepared statements when using mysqli? Snippet: <?php $conn = require_once 'dbconn.php'; $conn->autocommit(FALSE); $stmt_ins_option = $conn->prepare('INSERT INTO options(option_name) VALUES(?)'); $option_name = 'foo'; $stmt_ins_option->bind_param('s', $option_name); $stmt_ins_option->execute(); $conn->commit(); if($conn->errno) { $conn->rollback(); echo $conn->error; } It won't add it a second time because there's a UNIQUE constraint on that

Sending an array of parameters to bind_param

血红的双手。 提交于 2019-12-25 05:13:10
问题 I have the parameters to send to a prepared statement in an array, I am using call_user_func_array and using it as such call_user_func_array(array($stmt, "bind_param"), array_merge(array($types), $params_fixed)) , where $types contains the types and $params_fixed contains the parameters. I ran it and got the error Warning: Parameter 2 to mysqli_stmt::bind_param() expected to be a reference, value given in ... , I searched for this error and an answer was to send the parameters by reference so

inner join wont work with mysqli prepared statement in php

五迷三道 提交于 2019-12-25 04:14:18
问题 I can't seem to get this statement or statements alike to work with prepared queries, the code works just fine below: $DBH = getDBH(); $stmt = $DBH->prepare("SELECT a.id, a.title, a.photo FROM tag t INNER JOIN tag_reference atx ON t.tag_id = atx.tag_id INNER JOIN articles a ON atx.article_id = a.id WHERE t.tag_name = 'example'"); $stmt->execute(); $stmt->bind_result($id,$title,$photo); $stmt->fetch(); but when I change t.tag_name = '?' it gives me an error that the amount of parameters do not

php unsuccessful while loop within prepared statements

﹥>﹥吖頭↗ 提交于 2019-12-25 04:07:26
问题 code below is a part of my sitemap.xml file. My aim is to write the last modified date of my approved articles. There are 2 possibilities for this data. If article has no approved comment, then lastmod is the approval date of the article. If article has at least 1 approved comment, then lastmod is the approval date of the last approved comment. Errors in my output are: There are some articles in my db that has no comments but also these commentless articles get the approval date of last

prepared statement get inserted row

末鹿安然 提交于 2019-12-25 03:15:26
问题 I am using prepared statement to make insert in following way: String query = "Insert into ROLE (ROLEID,ROLENAME,TYPEID,UPDATETIMESTAMP) values (?,?,?,?)"; Class.forName(driver); conn = DriverManager.getConnection(url, userName, password); preparedStatement = conn.prepareStatement(query); preparedStatement.setInt(1, 0); preparedStatement.setString(2, roleName); preparedStatement.setInt(3, roleId); preparedStatement.setTimestamp(4,null); preparedStatement.executeUpdate(); Here ROLEID is the