Search Results

Search found 768 results on 31 pages for 'prepared'.

Page 3/31 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Mysqli prepared insert statements always returning false

    - by user1754679
    I'm writing prepared statements that are supposed to insert data into a table, on a database that's been pre-selected in the variable $GLOBALS['mysqli']. The connection has been tested, and that's not the problem I'm having. I'm only running into trouble whenever my prepared statement involves INSERT INTO. I know the tablename, and field names are correct, but $stmt is ALWAYS false. What gives? $stmt = $GLOBALS['mysqli']->prepare("INSERT INTO audit_RefreshCount (user, count, lastrefresh) values (?,?,?)"); if ($stmt == TRUE) { $stmt->bindParam('ssi', $_SESSION['username'], '0', time()); //$stmt->bind_Param('ssi', $_SESSION['username'], '0', time()); // Also doesn't work. $stmt->execute(); }

    Read the article

  • Reusing an anonymous parameter in a prepared statement

    - by Chris Lieb
    I am customizing the insert SQL generated by hibernate and have hit an issue. When Hibernate generates the query by itself, it inserts data into the first two columns of the table, but this causes a database error since all four columns of the table are non-nullable. For the insert to be performed properly, it must insert the same data into two columns of the new record. This means that I need Hibernate to bind the same data to two different parameters in the query (prepared statement) that I am writing. Is there some SQL syntax that allows me to refer to anonymous parameters bound to a prepared statement in an order different from which they are bound? Details REF_USER_PAGE_XREF ---------------------------------------- PK FK1 | NETWORK_ID | VARCHAR2(100) PK FK1 | PAGE_PATH | VARCHAR2(1000) | USER_LAST_UPDT | VARCHAR2(100) | TMSP_LAST_UPDT | DATE insert into REF_USER_ROLE_XREF( NETWORK_ID, PAGE_PATH, TMSP_LAST_UPDT, USER_LAST_UPDT) values ( ?, /* want to insert the same data here */ ?, ?, /* and here */ (select to_char(sysdate, 'DD-MON-YY') from dual) I want to insert the same data into the first and third anonymous parameters.

    Read the article

  • Prepared transactions with Postgres 8.4.3 on CentOS

    - by peter
    I have set 'max_prepared_transactions' to 20 in the local postgres.config and yet the transaction fails with the following error trace (but only on Linux). Since in Windows the same code works seamlessly I am wandering if this isn't an issue of permission. What would be the solution? Thanks Peter 372300 [Atomikos:7] WARN atomikos - XA resource 'XADBMS': rollback for XID '3137332E3230332E3132362E3139302E746D30303030313030303037:3137332E3230332E3132362E3139302E746D31' raised -3: the XA resource detected an internal error org.postgresql.xa.PGXAException: Error rolling back prepared transaction at org.postgresql.xa.PGXAConnection.rollback(PGXAConnection.java:357) at com.atomikos.datasource.xa.XAResourceTransaction.rollback(XAResourceTransaction.java:873) at com.atomikos.icatch.imp.RollbackMessage.send(RollbackMessage.java:90) at com.atomikos.icatch.imp.PropagationMessage.submit(PropagationMessage.java:86) at com.atomikos.icatch.imp.Propagator$PropagatorThread.run(Propagator.java:62) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:651) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:676) at java.lang.Thread.run(Thread.java:595) Caused by: org.postgresql.util.PSQLException: ERROR: prepared transaction with identifier "1096044365_MTczLjIwMy4xMjYuMTkwLnRtMDAwMDEwMDAwNw==_MTczLjIwMy4xMjYuMTkwLnRtMQ==" does not exist at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2062) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1795) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:479) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:353) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:299) at org.postgresql.xa.PGXAConnection.rollback(PGXAConnection.java:347)

    Read the article

  • SQL Injection When Using MySQLi Prepared Statements

    - by Sev
    If all that is used to do any and all database queries is MySQLi prepared statements with bound parameters in a web-app, is sql injection still possible? Notes I know that there are other forms of attack other than sql-injection, but my question is specific to sql-injection attacks on that particular web application only.

    Read the article

  • PHP Prepared Statement Returns -1

    - by pws5068
    I've been using prepared statements for a little while now and I've never had any problems. Now I'm trying to: $sql="SELECT PhotoID,Caption FROM Photos WHERE EntityID=? AND TypeID=? LIMIT ?,?"; $iDB = new mysqliDB(); // Extends mysqli $stmt = $iDB->prepare($sql); $stmt->bind_param('iiii',$entityID,$typeID,$minRange,$maxRange); $stmt->execute(); $stmt->bind_result($photoID,$caption); echo("Affected={$stmt->affected_rows}"); This prints -1. I have triple tested that all 4 values in bindParam are set, and that the sql query works when pasted into myAdmin with the respective values. Any idea what may be causing this?

    Read the article

  • MySqli Prepared Statment Fetch Row

    - by pws5068
    I'm looking for an efficient way to select a specific row with a php prepared statement. $iDB = new mysqliDB(); $stmt = $iDB->prepare($sql); $stmt->bind_param('s',$searhStr); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($objID,$typeID,$year,$updated); // Now jump to row $rowNumber echo("Obj ID = {$objID}"); Any suggestions? Thanks!

    Read the article

  • MySQLi Prepared Statement Query Issue

    - by Benjamin Flak
    I'm relatively new to MySQLi prepared statements, and running into an error. Take this code: $user = 'admin'; $pass = 'admin'; if ($stmt = $mysqli->query("SELECT * FROM members WHERE username='$user' AND password='$pass'")) { echo $stmt->num_rows; } This will display "1", as it should. This next piece of code though, returns "0": $user = 'admin'; $pass = 'admin'; if ($stmt = $mysqli->prepare("SELECT * FROM members WHERE username=? AND password=?")) { $stmt->bind_param("ss", $user, $pass); $stmt->execute(); echo $stmt->num_rows; } Any ideas why?

    Read the article

  • PHP: prepared statement, IF statement help needed

    - by JGreig
    I have the following code: $sql = "SELECT name, address, city FROM tableA, tableB WHERE tableA.id = tableB.id"; if (isset($price) ) { $sql = $sql . ' AND price = :price '; } if (isset($sqft) ) { $sql = $sql . ' AND sqft >= :sqft '; } if (isset($bedrooms) ) { $sql = $sql . ' AND bedrooms >= :bedrooms '; } $stmt = $dbh->prepare($sql); if (isset($price) ) { $stmt->bindParam(':price', $price); } if (isset($sqft) ) { $stmt->bindParam(':price', $price); } if (isset($bedrooms) ) { $stmt->bindParam(':bedrooms', $bedrooms); } $stmt->execute(); $result_set = $stmt->fetchAll(PDO::FETCH_ASSOC); What I notice is the redundant multiple IF statements I have. Question: is there any way to clean up my code so that I don't have these multiple IF statements for prepared statements?

    Read the article

  • inserting datetimes into database using java

    - by gordatron
    Hi, I am wanting to insert a datetime into a MySql data base using Java and a prepared statement: Calendar cal = Calendar.getInstance(); PreparedStatement stmnt = db.PreparedStatement("INSERT INTO Run " + "(Time) VALUE (?) "); stmnt.setDate(1, new java.sql.Date(cal.getTime())); stmnt.executeQuery(); NOTE: thre is currently an error - cannot find symbol (java.sql.Date) line 4 here db is an instance of a sort of wrapper class that exposes what I need from java.sql - its just getting a prepared statement from my connection object here. Time (the column) is a date time in my database, and I can only see sedDate and setTime method but I want to store both - also my code does not work anyway ;-) if anyone could give me some pointers on inserting a combined date time (current time would be a great help as that's my first goal) into a MySql DB using a prepared statement I would be very grateful. Thanks

    Read the article

  • MySQLi Insert prepared statement via PHP

    - by Jimmy
    Howdie do, This is my first time dealing with MySQLi inserts. I had always used mysql and directly ran the queries. Apparently, not as secure as MySQLi. Anywho, I'm attempting to pass two variables into the database. For some reason my prepared statement keeps erroring out. I'm not sure if it's a syntax error, but the insert just won't work. I've updated the code to make the variables easier to read Also, the error is specifically, Error preparing statement. I've updated the code, but it's not a pHP error. It's a MySQL error as the script runs but fails at the execution of: if($stmt = $mysqli - prepare("INSERT INTO subnets (id, subnet, mask, sectionId, description, vrfId, masterSubnetId, allowRequests, vlanId, showName, permissions, pingSubnet, isFolder, editDate) VALUES ('', ?, ?, '1', '', '0', '0', '0', '0', '0', '{"3":"1","2":"2"}', '0', '0', 'NULL')")) { I'm going to enable MySQL error checking. I honestly didn't know about that. <?php error_reporting(E_ALL); function InsertIPs($decimnal,$cidr) { error_reporting(E_ALL); $mysqli = new mysqli("localhost","jeremysd_ips","","jeremysd_ips"); if(mysqli_connect_errno()) { echo "Connection Failed: " . mysqli_connect_errno(); exit(); } if($stmt = $mysqli -> prepare("INSERT INTO subnets (id, subnet, mask,sectionId,description,vrfld,masterSubnetId,allowRequests,vlanId,showName,permissions,pingSubnet,isFolder,editDate) VALUES ('',?,?,'1','','0','0','0','0','0', '{'3':'1','2':'2'}', '0', '0', NULL)")) { $stmt-> bind_param('ii',$decimnal,$cidr); if($stmt-> execute()) { echo "Row added successfully\n"; } else { $stmt->error; } $stmt -> close; } } else { echo 'Error preparing statement'; } $mysqli -> close(); } $SUBNETS = array ("2915483648 | 18"); foreach($SUBNETS as $Ip) { list($TempIP,$TempMask) = explode(' | ',$Ip); echo InsertIPs($Tempip,$Tempmask); } ?> This function isn't supposed to return anything. It's just supposed to perform the Insert. Any help would be GREATLY appreciated. I'm just not sure what I'm missing here

    Read the article

  • Setting UIActivityIndicatorView while view is prepared

    - by iFloh
    Hi, I have a UITabbBarController with a UITableView. Under certain circumstances the TabBarControllers dataset requires updating when a user arrives from another view, e.g. the initial load when the TabBarController is called the first time, or when the settings are changed. This dataset update takes about 2 seconds and I want to show an UIActivityIndicatorView. Trouble is that when I enter from another view I don't know which view to attach it to, since the loading of the tabbarController is carried out in the viewWillAppear method. Any clues how I can go about this?

    Read the article

  • Getting Prepared/Planning

    - by The.Anti.9
    For the first time, I am trying to create a rather large .NET project. I think the largest one I have made so far was about 6 classes, but this one is already at 14. For the section I'm starting to work on, I'm having some trouble putting everything together in my head, which is what I normally do. I think it's just a little too complex for that. I want to plan it out, and I want some way to visualize it and be able to play with it and manipulate the structure easily. Is there any sort of (free) program I can use to do this?

    Read the article

  • Prepared statement initialized tiwice and closed once

    - by sonam
    Hi, I want to know that if a PreparedStatement object is initialized twice the way shown in code snippet below and closed only once in finally block, will it fail to close? I am not getting any error in this code but will it be a better idea to use 2 different preparedStatements instead of one. I think it fails to close the preparedStatement at #1. Connection conn = null; PreparedStatement ps = null; try { conn = getConnection(); ps = conn.prepareStatement(QueryUtil.UPDATE_POLICY_DETAILS); // #1 ps.setInt(1, iCancellationPolicyId); ps.executeUpdate(); //some code here ps = conn.prepareStatement(QueryUtil.UPDATE_POLICY_CHARGES); // #2 ps.setInt(1, iCancellationPolicyId); ps.executeUpdate(); //some code here } catch (SQLException sqlExp) { sqlExp.printStackTrace(); LOG.fatal(sqlExp); } finally { conn.close(); ps.close(); }

    Read the article

  • MySQL: How to consume/discard the result of a query?

    - by GetFree
    I have a stored procedure which executes an optimize table statement for every table in a DB. Those optimize table statements are prepared statements of course (they have to be built at runtime) and I need to call that procedure from PHP using ext/mysql API. Unfortunately, ext/mysql does't support doing such thing because optimize table returns a result set and in order to handle that, the new mysql protocol is required, which is supported by the "new" ext/mysqli API. Well... there are several things I dont have control over, so it's not in my posibilities to upgrade to ext/mysqli any time soon, nor can I implement the procedure as PHP code rather than sql code. So I thought if it would be possible somehow to consume/discard the result of optimize table inside the stored procedure so that ext/mysql doesn't complain about it. One thing to consider is that since the optimize table statements are prepared statements, you can't use a cursor over them.

    Read the article

  • MySQLI Prepared Statement Not Binding Properly

    - by Sev
    Any reason why the following code won't work? $dbconnection = db::getInstance(); //this is a singleton db class $stmt = $dbconnection->prepare("SELECT `id` from `table` where `username`=?"); $stmt->bind_param("s", $username); $stmt->execute(); $stmt->bind_result($uid); $stmt->fetch(); echo $uid; The same connection method is used elsewhere, and it works there. The only difference on that other page where it works, is that there are multiple rows fetched, not just one.

    Read the article

  • PreparedStatement

    - by Steel Plume
    Hello, in the case of using PreparedStatement with a single common connection without any pool, can I recreate an instance for every dml/sql operation mantaining the power of prepared statements? I mean: for (int i=0; i<1000; i++) { PreparedStatement preparedStatement = connection.prepareStatement(sql); preparedStatement.setObject(1, someValue); preparedStatement.executeQuery(); preparedStatement.close(); } instead of: PreparedStatement preparedStatement = connection.prepareStatement(sql); for (int i=0; i<1000; i++) { preparedStatement.clearParameters(); preparedStatement.setObject(1, someValue); preparedStatement.executeQuery(); } preparedStatement.close(); my question arises by the fact that I want to put this code into a multithreaded environment, can you give me some advice? thanks

    Read the article

  • Reusing a PreparedStatement multiple times

    - by Steel Plume
    Hello, in the case of using PreparedStatement with a single common connection without any pool, can I recreate an instance for every dml/sql operation mantaining the power of prepared statements? I mean: for (int i=0; i<1000; i++) { PreparedStatement preparedStatement = connection.prepareStatement(sql); preparedStatement.setObject(1, someValue); preparedStatement.executeQuery(); preparedStatement.close(); } instead of: PreparedStatement preparedStatement = connection.prepareStatement(sql); for (int i=0; i<1000; i++) { preparedStatement.clearParameters(); preparedStatement.setObject(1, someValue); preparedStatement.executeQuery(); } preparedStatement.close(); my question arises by the fact that I want to put this code into a multithreaded environment, can you give me some advice? thanks

    Read the article

  • Reusing of a PreparedStatement between methods?

    - by MRalwasser
    We all know that we should rather reuse a JDBC PreparedStatement than creating a new instance within a loop. But how to deal with PreparedStatement reuse between different method invocations? Does the reuse-"rule" still count? Should I really consider using a field for the PreparedStatement or should I close and re-create the prepared statement in every invocation? (Of course an instance of such a class would be bound to a Connection which might be a disadvantage) I am aware that the ideal answer might be "it depends". But I am looking for a best practice for less experienced developers that they will do the right choice in most of the cases.

    Read the article

  • Can't bind string containing @ char with mysqli_stmt_bind_param

    - by Tirithen
    I have a problem with my database class. I have a method that takes one prepared statement and any number of parameters, binds them to the statement, executes the statement and formats the result into a multidimentional array. Everthing works fine until I try to include an email adress in one of the parameters. The email contains an @ character and that one seems to break everything. When I supply with parameters: $types = "ss" and $parameters = array("[email protected]", "testtest") I get the error: Warning: Parameter 3 to mysqli_stmt_bind_param() expected to be a reference, value given in ...db/Database.class.php on line 63 Here is the method: private function bindAndExecutePreparedStatement(&$statement, $parameters, $types) { if(!empty($parameters)) { call_user_func_array('mysqli_stmt_bind_param', array_merge(array($statement, $types), &$parameters)); /*foreach($parameters as $key => $value) { mysqli_stmt_bind_param($statement, 's', $value); }*/ } $result = array(); $statement->execute() or debugLog("Database error: ".$statement->error); $rows = array(); if($this->stmt_bind_assoc($statement, $row)) { while($statement->fetch()) { $copied_row = array(); foreach($row as $key => $value) { if($value !== null && mb_substr($value, 0, 1, "UTF-8") == NESTED) { // If value has a nested result inside $value = mb_substr($value, 1, mb_strlen($value, "UTF-8") - 1, "UTF-8"); $value = $this->parse_nested_result_value($value); } $copied_row[$ke<y] = $value; } $rows[] = $copied_row; } } // Generate result $result['rows'] = $rows; $result['insert_id'] = $statement->insert_id; $result['affected_rows'] = $statement->affected_rows; $result['error'] = $statement->error; return $result; } I have gotten one suggestion that: the array_merge is casting parameter to string in the merge change it to &$parameters so it remains a reference So I tried that (3rd line of the method), but it did not do any difference. How should I do? Is there a better way to do this without call_user_func_array?

    Read the article

  • Using array instead of lots of db queries in PHP

    - by Tural Teyyuboglu
    My function looks like that. It works but does lots of work (recursively calls itself and does lots of db queries.). There must be another way to do same thing but with array (with one query). I can't figure out how to modify this function to get it work with array. Please help. function genMenu($parent, $level, $menu, $utype) { global $db; $stmt=$db->prepare("select id, name FROM navigation WHERE parent = ? AND menu=? AND user_type=?") or die($db->error); $stmt->bind_param("iii", $parent, $menu, $utype) or die($stmt->error); $stmt->execute() or die($stmt->error); $stmt->store_result(); /* bind variables to prepared statement */ $stmt->bind_result($id, $name) or die($stmt->error); if ($level > 0 && $stmt->num_rows > 0) { echo "\n<ul>\n"; } while ($stmt->fetch()) { echo "<li>"; echo '<a href="?page=' . $id . '">' . $name . '</a>'; //display this level's children genMenu($id, $level+1, $menu, $utype); echo "</li>\n\n"; } if ($level > 0 && $stmt->num_rows > 0) { echo "</ul>\n"; } $stmt->close(); }

    Read the article

  • PHP PDO MySQL IN (?,?,?...

    - by nute
    I want to write a MySQL statement like: SELECT * FROM someTable WHERE someId IN (value1, value2, value3, ...) The trick here is that I do not know ahead of time how many values there will be in the IN(). Obviously I know I can generate the query on the go with string manipulations, however since this will run in a loop, I was wondering if I could do it with a PDO PreparedStatement. Something like: $query = $PDO->prepare('SELECT * FROM someTable WHERE someId IN (:idList)'); $query->bindValue(':idList', implode(',', $idArray)); Is that possible?

    Read the article

  • Problems with Date, preparedStatement, JDBC and PostgreSQL

    - by GuidoMB
    I Have to get a movie from a PostgreSQL database that matches a given title and release date. title is a character(75) and releaseDate is a date. I Have this code: String query = "SELECT * FROM \"Movie\" WHERE title = ? AND \"releaseDate\" = ?)"; Connection conn = connectionManager.getConnection(); PreparedStatement stmt = conn.prepareStatement(query); java.sql.Date date = new java.sql.Date(releaseDate.getTime()); stmt.setString(1, title); stmt.setDate(2, date); ResultSet result = stmt.executeQuery(); but it's not working because the releaseDate is not matching when it should. The query SELECT * FROM "Movie" WHERE title = A_MOVIE AND "releaseDate" = A_DATE works perfectly on a command shell using psql

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >