prepared-statement

SQLite in Ruby: Prepared statement cutting UTF-8 input

半城伤御伤魂 提交于 2020-01-03 04:40:10
问题 I'm having an issue where variables are cut when they contain special characters. This is a complete reproducable program that should run in irb: require 'sqlite3' db = SQLite3::Database.new ":memory:" db.query "CREATE TABLE test (id INTEGER PRIMARY KEY, key TEXT, value TEXT)" db.query "INSERT INTO test(key, value) VALUES(?, ?)", "foo", "baræøå" db.get_first_value "SELECT value FROM test" This yields: => bar If I have understood it correctly, the database should default to UTF-8, and indeed,

PHP mysqli prepared statements removing leading zeros

大兔子大兔子 提交于 2020-01-03 03:40:17
问题 Im trying to enter a phone number into my database, the column is set as varchar(15) and inside phpmyadmin it will accept a phone number with a leading 0 (07712123123 for example). In my PHP script i have the variable $contactNo which is a string containing 07712123123 but when I use my prepared statement to input the data into the database the leading zero is removed. How can I stop this? // Insert data into customer_accounts if($stmt = $mysqli -> prepare("INSERT INTO customer_accounts

Variable amount of columns returned in mysqli prepared statement

有些话、适合烂在心里 提交于 2020-01-03 03:02:57
问题 I have a situation where a dynamic query is being generated that could select anywhere from 1 to over 300 different columns across multiple tables. It currently works fine just doing a query, however the issue I'm running into in using a prepared statement is that I do not know how to handle the fact that I don't know how many columns I will be asking for each time and therefor don't know how to process the results. The reason I believe a bind statement will help is because once this query is

Variable amount of columns returned in mysqli prepared statement

浪尽此生 提交于 2020-01-03 03:02:07
问题 I have a situation where a dynamic query is being generated that could select anywhere from 1 to over 300 different columns across multiple tables. It currently works fine just doing a query, however the issue I'm running into in using a prepared statement is that I do not know how to handle the fact that I don't know how many columns I will be asking for each time and therefor don't know how to process the results. The reason I believe a bind statement will help is because once this query is

Fetching rows from database via a prepared statement

随声附和 提交于 2020-01-03 02:49:08
问题 I initially created the below query to return some results from my database. $result = mysqli_query($con, "SELECT bookingId, locationName FROM bookings WHERE username = '$one'"); $output = array(); while($row = mysqli_fetch_assoc($result)) { $output[]=$row; } print(json_encode($output)); However, I now want to use prepared statements and have tried the below. But It always returns [] . Is this the correct way to return rows via a prepared statement. $stmt = $con->prepare('SELECT bookingId

Bind Results in C# using SQL prepared statements

允我心安 提交于 2020-01-02 20:45:55
问题 Using this: SqlConnection myConnection = new SqlConnection("Data Source=.\\SERVER;Initial Catalog=DB;Integrated Security=True;TrustServerCertificate=True;User Instance=False"); myConnection.Open(); SqlCommand myCommand = new SqlCommand("SELECT BusinessName FROM Businessess WHERE BusinessID = @Param2", myConnection); SqlParameter myParam2 = new SqlParameter("@Param2", SqlDbType.Int, 4); myParam2.Value = 1; myCommand.Parameters.Add(myParam2); MessageBox.Show(myCommand); //How do I bind results

Inserting date into MySQL database using a PreparedStatement

血红的双手。 提交于 2020-01-02 05:27:08
问题 I want to update the string date into MySQL database using prepared statement. I have tried a lot and always got error java.util.Date cannot parse into java.sql.Date or vise versa. I didn't import anything here. Please import according to your answer. public class Date1 { public static void main(String args[]) { String source="2008/4/5"; SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); java.sql.Date d=(Date) format.parse(source); Class.forName("com.mysql.jdbc.Driver"); Connection

ClassCastException - oracle.jdbc.OraclePreparedStatement

天大地大妈咪最大 提交于 2020-01-02 05:15:10
问题 I'm encountering an aggravating issue, here's the facts - I'm registering a return parameter specific and to do so I'm casting a java.sql.PreparedStatement to oracle.jdbc.OraclePreparedStatement. ((OraclePreparedStatement) getStatement()) .registerReturnParameter(index, sqlType); This works great when I run this from Eclipse and it even runs as expected on our development server. However, it's when I move it to our testing server where I hit an unexpected error... oracle.jdbc.driver

PDO prepared statement with optional parameters

半城伤御伤魂 提交于 2020-01-01 11:37:08
问题 I'm kind of new with PDO and currently developing the API call that returns search results. How do I set a prepare statement if there are 2 optional parameters for the search query? $app->get('/get/search', function () { $sql = 'SELECT * FROM user WHERE name LIKE :name AND city = :city AND gender = :gender'; try { $stmt = cnn()->prepare($sql); $stmt->bindParam(':name', '%'.$_GET['name'].'%', PDO::PARAM_STR); $stmt->bindParam(':city', '%'.$_GET['city'].'%', PDO::PARAM_STR); $stmt->bindParam('

Are there any disadvantages using Preparedstatement compared to Statement

≯℡__Kan透↙ 提交于 2020-01-01 09:33:42
问题 I was going through differences between Statement and PreparedStatement in JDBC and saw so many advantages here and here with PreparedStatement in comparison with Statement. Some of my colleague was asking why we still need Statement and why it is not deprecated looking at the advantages of PreparedStatement. So is there any reason why we still have the Statement in JDBC API? 回答1: PreparedStatement is used to handle the dynamic SQL queries, where Statement is used to handle static SQL queries