prepared-statement

php mysqli prepared statement

北城以北 提交于 2019-11-29 18:40:01
Hey, I have a quick one. Is there any way to include a variable into a prepared query? example: $sql = "SELECT id, title, author, LEFT(description, 40) AS excerpt, image_small, image_med, date FROM posts ORDER BY id DESC LIMIT $start, $postsPerPage"; $result = $connect->prepare($sql) or die ('error'); $result->execute(); $result->bind_result($id, $title, $author, $excerpt, $image_small, $image_med, $date); Thanks! you want the following: $start = 1; $postsPerPage = 1; $sql = "SELECT id, title, author, LEFT(description, 40) AS excerpt, image_small, image_med, date FROM posts ORDER BY id DESC

Adding a row with columns that have sequenced primary and foreign key JDBC

妖精的绣舞 提交于 2019-11-29 18:07:15
My program has an add item and finish transaction option. The FinishTransaction class asks the user to input the customer's information, method of payment, and the payment. The total payment is displayed at the window. When the user click the checkout button, the data should be transferred from the CUSTOMER table (insert the customer's information), ORDERS table (insert the item's information bought), and the TRANSACTION table (insert the transaction information). The transaction table has a column of TRANS_CUSTNUM that is a foreign key referenced to the CUST_NUM in the CUSTOMER table. My

Passing an Array to a SQL query using Java's PreparedStatement

岁酱吖の 提交于 2019-11-29 17:23:11
I've been having a little trouble passing an array into a SQL query using Java's prepared statements. I had first tried the sourceforge driver, however I would get the AbstractMethodError when I call setArray method. Not knowing the solution to that I swapped to the Microsoft sqlserver driver, but now I get a different error entirely, which is "java.sql.SQLFeatureNotSupportedException: This operation is not supported." Tried a whole bunch of things to try and resolve this but nothing appears to work. My Java code looks similar to examples I've seen here and on the internet, and is as follows,

Is there a reason for never closing a JDBC connection?

一世执手 提交于 2019-11-29 17:21:17
I'm reading a code from the last developer that worked on the system and he never closes any connections with the database. He only closes PreparedStatement and ResultSet connections but never the Connection. The system does not use a connection pool. Is there any reason not to close everything ( Connection , PreparedStatement and ResultSet )? There is no good reason for this, it will result in a very brittle application. It's easy for a database connection to go stale if there's a network problem or if the database doesn't respond for a little while, and with the reliance on a single existing

Prepared statements and second order SQL injections

☆樱花仙子☆ 提交于 2019-11-29 17:20:25
I have read somewhere here that using prepared statements in PDO makes your app only immune to first order SQL injections, but not totally immune to second order injections. My question is: if we used prepared statements in all queries inlcuding SELECT queries and not only in INSERT query, then how can a second order sql injection be possible? For example in the following queries there is no chance for a 2nd order injection: write: INSERT INTO posts (userID,text,date) VALUES(?,?,?) read: SELECT * FROM posts WEHRE userID=? delete: DELETE FROM posts WHERE userID=? What you have read is a plain

MySQLi : Inserting multiple rows with one prepared statement

情到浓时终转凉″ 提交于 2019-11-29 17:08:24
I made a script that creates a raw query string and then inserts the hundreds of rows in one statement. It works but does not offer the protections that prepared statements do. I then modified my script to add prepared statements. It works however, it is significantly slower. The script with prepared statements takes much longer to insert the rows than the raw query script, due to the script running through each prepared insert statement one row at a time rather than inserting hundred of rows at a time. Here's a snippet of the prepared statement code: for( $j = 0; $j < $abilitiesMax - 2; $j++

MYSQLi bind_result is returning null

筅森魡賤 提交于 2019-11-29 16:56:55
I am trying to output the variables that I get from the database in my query but nothing is being returned. Using MYSQLi prepared statements. Please see code below: $stmt = $con->prepare("SELECT first_name, last_name FROM transactions WHERE order_id = ?"); $stmt->bind_param('i', $order_id); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($first_name, $last_name); $stmt->close(); // Output review live to page echo $first_name; I cannot see where I am going wrong? PS I am new to prepared statements so please go easy on me! you forgetting the line to fetch the result. fetch() . try

JDBC, MySQL: getting bits into a BIT(M!=1) column

老子叫甜甜 提交于 2019-11-29 16:45:39
I'm new to using JDBC + MySQL. I have several 1/0 values which I want to stick into a database with a PreparedStatement. The destination column is a BIT(M!=1). I'm unclear on which of the setXXX methods to use. I can find the references for what data comes out as easily enough, but how it goes in is eluding me. The values effectively live as an ordered collection of booleans in the objects used by the application. Also, I'll occasionally be importing data from flat text files with 1/0 characters. To set a BIT(M) column in MySQL For M==1 setBoolean(int parameterIndex, boolean x) From the

PreparedStatement question in Java against Oracle

六眼飞鱼酱① 提交于 2019-11-29 16:39:48
I'm working on the modification of some code to use preparedStatement instead of normal Statement, for security and performance reason. Our application is currently storing information into an embedded derby database, but we are going to move soon to Oracle. I've found two things that I need your help guys about Oracle and Prepared Statement : 1- I've found this document saying that Oracle doesn't handle bind parameters into IN clauses, so we cannot supply a query like : Select pokemon from pokemonTable where capacity in (?,?,?,?) Is that true ? Is there any workaround ? ... Why ? 2- We have

Mysql update query with prepared statement is giving error

谁说我不能喝 提交于 2019-11-29 16:27:06
I am getting the following error in the code below. Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement in C:\wamp\www\purev\admin\edit.php on line 39 if(isset($_POST['submit'])){ $post_title = $_POST['posttitle']; $content = $_POST['content']; $author_name = $_POST['authorname']; $category = $_POST['category']; $post_date = $_POST['postdate']; if(isset($_FILES['image']['name']) && ($_FILES['image']['name'] !="")){ $size=$_FILES['image']['size']; $temp=$_FILES['image']['tmp_name']; $type=$_FILES['image']['type']; $image_name=$_FILES[