prepared-statement

mysqli_fetch_assoc() expects parameter / Call to a member function bind_param() errors. How to get the actual mysql error and fix it?

主宰稳场 提交于 2019-12-02 18:24:49
问题 In my local/development environment, the MySQLi query is performing OK. However, when I upload it on my web host environment, I get this error: Fatal error: Call to a member function bind_param() on a non-object in... Here is the code: global $mysqli; $stmt = $mysqli->prepare("SELECT id, description FROM tbl_page_answer_category WHERE cur_own_id = ?"); $stmt->bind_param('i', $cur_id); $stmt->execute(); $stmt->bind_result($uid, $desc); To check my query, I tried to execute the query via

Using prepared statements with JDBCTemplate

旧巷老猫 提交于 2019-12-02 17:32:24
I'm using the JDBC template and want to read from a database using prepared statements. I iterate over many lines in a .csv file, and on every line I execute some SQL select queries with corresponding values. I want to speed up my reading from the database but I don't know how to get the JDBC template to work with prepared statements. There is the PreparedStatementCreator and the PreparedStatementSetter . As in this example both of them are created with anonymous inner classes. But inside the PreparedStatementSetter class I don't have access to the values I want to set in the prepared

How to use prepare() with dynamic column names?

江枫思渺然 提交于 2019-12-02 17:19:52
问题 I have a function that takes an sql table column name string as a parameter, returns 1 string result: function myFunction($column_name) { return $wpdb->get_var($wpdb->prepare("SELECT %s FROM myTable WHERE user_id=%s", $column_name, $current_user->user_login)); } However, this code does NOT work, since with the nature of prepare, I can't use a variable for column names (and table names). This works, but I think it poses a security issue: return $wpdb->get_var('SELECT ' . $column_name . ' FROM

Ways of concatenating string in a prepared statement [duplicate]

纵然是瞬间 提交于 2019-12-02 16:53:13
问题 This question already has answers here : What is a NullPointerException, and how do I fix it? (12 answers) Closed 3 years ago . I have a web application that needs to be stored its data on specific tables depending on the user's input. e.g. if a user input Code "A" their data will be saved to DatabaseA, while if a user input Code "B", the data will be saved to DatabaseB. I need to know if there is way to manipulate the prepared statement in order to just concatenate the code into the end of

Invalid column index using PreparedStatement

巧了我就是萌 提交于 2019-12-02 14:24:33
问题 I am trying to query same data. But the preparedStatement thrown an SQLException about wrong indexing even though the index start from 1 as the documentation said. Here is the function: public List<Paper1> search(String keyword) throws NotConnectedException { List<Paper1> papers = new ArrayList<>(); try { PreparedStatement searchKeyword = connection.prepareStatement("SELECT title, registered FROM paper " + "WHERE title LIKE '%?%'"); searchKeyword.setString(1, keyword); ResultSet rs =

INSERT several rows with a prepared statement in a loop

冷暖自知 提交于 2019-12-02 14:23:57
Sqlserv php error when inserting using array portion ARRAY PREPRATION foreach ($data as $rs) { $params []="({$rs->hd},'{$rs->dvn}',{$rs->mth},{$rs->yr},{$rs->stid},{$rs->prcd},'{$rs->prnm}',{$rs->prte},{$rs->ssl},{$rs->clsk},1)"; } INSERT INTO STATEMENT: $SqlInsert="insert into SQl_test (Ss_Hq_cd,Ss_division,Ss_month,Ss_yr,Ss_stk_Id,Ss_prod_cod,Ss_prod_name,ss_prod_rate,Ss_Sale,Ss_Cl_stk,ss_tran_stat) values(?,?,?,?,?,?,?,?,?,?,?) "; $stmt = sqlsrv_query( $conn, $SqlInsert,$params); EROOR: Error in statement preparation/execution.\n" Array ( [0] => Array ( [0] => 22018 [SQLSTATE] => 22018 [1]

Fatal error: Call to a member function prepare() on null

荒凉一梦 提交于 2019-12-02 13:21:50
I'm getting this error and i can't find whats wrong. I've read through the other posts about this error but none of them seemed to help. Fatal error: Call to a member function prepare() on null on line 92 <?php include 'config.php'; $lengd = $_POST["lengd"]; $height = $_POST["height"]; $width = $_POST["width"]; $min_lengd = $lengd * 0.9; $max_lengd = $lengd * 1.1; $min_height = $height * 0.9; $max_height= $height * 1.1; $min_width = $width * 0.9; $max_width= $width * 1.1; $sql = "SELECT lengd, height, width FROM filters; WHERE $lengd BETWEEN :min_lengd AND :max_lengd AND $height BETWEEN :min

try and catch with a prepared statement

折月煮酒 提交于 2019-12-02 13:21:20
I have had a very hard time with this query and it was suggested to me to learn try and catch blocks to more easily figure out what is wrong. So this is my first attempt at it. I am getting the error for my @stmt2 not being defined for my print_r($stmt2) line. Notice: Undefined variable: stmt2 This is my attempt at the try catch. Am I doing anything wrong with it for this error to come up? try { $con = mysqli_connect("localhost", "", "", ""); if (mysqli_connect_errno()) { throw new Exception("Connect failed: %s\n", mysqli_connect_error()); exit(); } $cid = $_GET['cid']; $tid = $_GET['tid'];

MySqli prepare statement error when used for LIKE

こ雲淡風輕ζ 提交于 2019-12-02 13:00:20
I'm trying to make a prepared statement for a LIKE query using php's mysqli extension. But no matter what I try, I always get this error: Fatal error: Problem preparing query (SELECT f.*,r.slug FROM `foods` AS f INNER JOIN `resturants` AS r ON f.`rest_id` = r.`rest_id` WHERE f.`name` LIKE CONCAT('%',"f", '%')) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''%',"f", '%')' at line 4 in /path/to/class.mysqli.php on line 462 I have tried the following queries to no avail: (The $s would be my string to search

Java MySQL preparedStatement Batch

北慕城南 提交于 2019-12-02 12:43:37
问题 I am trying to use the preparedStatement Batch but I am having a problem. The following code does not give me errors, but it inserts in the table only last key of the map and I do not know why. It will be surely a very stupid error, but this is the first time I use the addBatch() method.. Class.forName("com.mysql.jdbc.Driver"); this.connect = DriverManager.getConnection("jdbc:mysql://localhost/" + this.database + "?user=" + this.user + "&password=" + this.password); String s; for (String key