prepared-statement

mysql, prepared statements, and automatic type conversion

夙愿已清 提交于 2019-12-24 00:47:20
问题 I am getting different results performing the exact same query using regular statements and prepared statements, and I think it's a type conversion bug. mysql> show columns from server where field = "vlan"; +-------------+--------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+--------+------+-----+---------+-------+ | vlan | int(5) | YES | MUL | NULL | | +-------------+--------+------+-----+---------+-------+ mysql> select hostname from server

HSQLDB Statement and Java NaN doubles

烈酒焚心 提交于 2019-12-24 00:39:01
问题 I'm currently using HSQLDB to save java data. Within theses datas, there are some Double, and some of them can be of values of NaN (described as 0.0/0.0 in the javadoc). HSQLDB know how to handle these values in setDouble and setFloat of PreparedStatement . The thing is, I have to use a Statement object, not a precompiled stored procedure, and I just can't find a way to make it work. If you had the tinyest hint, it would be most welcome :) Thanks. EDIT : Here's the bunch of code I'm using :

How can I abstract mysqli prepared statements in PHP?

≯℡__Kan透↙ 提交于 2019-12-24 00:37:08
问题 I'm using my own class for database queries, extending mysqli: class iDatabase extends mysqli { public $errorMsg; private $totalQueries; private $stmt; public function __construct() { parent::__construct( 'localhost', 'asd', 'asd', 'asd' ); if ( mysqli_connect_errno() ) { $this->errorMsg = 'Could not connect to server.<br /><i>' . mysqli_connect_error() . '</i>.'; return; } parent::query( 'SET NAMES utf8' ); } } However I'm running into trouble when executing queries and getting back results.

How to use whitelists and prepared-statements with Postgresql in php?

社会主义新天地 提交于 2019-12-24 00:34:22
问题 I understand that I need to implement whitelists and prepared-statements into my php code. But I'm not sure how to do this with Postgresql and is it really necessary for my code? I'm using select lists to pass the users selected values to the query. <?php include "connect.php"; $table = $_POST['tableSelected']; $field = $_POST['fieldSelected']; $attribute = $_POST['attributeSelected']; $operator = $_POST['operatorSelected']; $fieldList = $_POST['fieldList']; $fieldstr = $fieldList . ",ST

Round bracket in string with JDBC prepared statement

感情迁移 提交于 2019-12-23 23:34:40
问题 Here is my Java JDBC code (modified and simplified for example): ps = connection.prepareStatement("SELECT a,b,c FROM mytable WHERE category ~ ?"); ps.setString(1, "my/super/category/abc(def"); ^ | +---------------------------------+ | //this character is problem result = ps.executeQuery(); It didn't work because of round bracket in string. How to escape round brackets in prepared statement? EDIT: based on my answer (see below) I do correct to question. 回答1: Will answer myself - problem is in

How to get array of row objects from my result in mysqli prepared query

大城市里の小女人 提交于 2019-12-23 22:25:25
问题 I would like to return all the results from my prepared query (mysqli) as objects in an array but i cant find a fetchall method or something similar. How do i go about this? public function getImageResults ($search_term) { if (empty($search_term)) return false; $image_query = $this->db_connection->stmt_init(); $image_query_sql = " SELECT Images.url as url FROM Images, ImageSearch, ImageSearchResults WHERE ImageSearch.search_string = ? AND ImageSearchResults.search_id = ImageSearch.id AND

type definition string doesn't match number of bind variables [duplicate]

拟墨画扇 提交于 2019-12-23 20:23:17
问题 This question already has answers here : mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables (3 answers) Closed 2 years ago . I use a dynamic database class I constructed for all my projects. Just started with a new one, and the class is giving me a hiccup. This is my code, not the details. But I recreated the error through minimal code. function vref($arr) { if (strnatcmp(phpversion(),'5.3') >= 0) {//Reference is required for PHP 5.3

Using REGEXP inside mysqli prepared statement in PHP

最后都变了- 提交于 2019-12-23 18:50:59
问题 I am trying to make a simple search process with (noob) codes like this: $prep->prepare("SELECT * FROM details WHERE id REGEXP '?'"); $prep->bind_param("s", $search_query); It gives me this warning: Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement I am guessing it could be because the question mark is also used for RegExp (optional previous character). Any idea about how to use REGEXP inside prepared statements (without

Is it necessary to close PreparedStatement before preparing another Statement

怎甘沉沦 提交于 2019-12-23 17:16:24
问题 Is it necessary to close ResultSet and PreparedStatement within one db.getConnection()? For the example below: Connection conn = db.getConnection(); PreparedStatement pstmt = conn.prepareStatement(firstsql); ResultSet r = pstmt.executeQuery(); // do something with the ResultSet r.close(); pstmt.close(); // do I need close the r and pstmt here? PreparedStatement pstmt = conn.prepareStatement(secondsql); ResultSet r = pstmt.executeQuery(); // do something with the ResultSet again r.close();

PDO and IS NOT NULL Function

爱⌒轻易说出口 提交于 2019-12-23 16:09:34
问题 I am new to PDO and I was wondering if there was an equivalent to a mysql statement that checks if a parameter is not null such as: SELECT * FROM table WHERE param IS NOT NULL I tried this: $pdo->prepare('SELECT * FROM ' . $tablename . ' WHERE ' . $field . ' = :' . $field . 'AND param IS NOT NULL'); without any success. I also looked on the web, but did not find anything relevan, can anyone help please ? 回答1: You can use any query in pdo that you could use in mysql directly but your way of