prepared-statement

Cant the prepared statement be used throught the transaction, from php?

Hi again, guys. I work on a LAPP environment (linux apache postgresql php), and i'm just triyn to find out how to use the prepared statement within the transaction (if is possible). I hope code will explain better then words: Example 1, simple transaction: BEGIN; INSERT INTO requests (user_id, description, date) VALUES ('4', 'This do...

Mysql Prepare Statement error while executing

Hi All, I am trying to create a table though prepare statement but it is giving me syntax error. well if o try to execute the same statement individually then it work fine. here's my statement - SET @Stmt1 = Concat('DROP TABLE IF EXISTS ',DB,'.`county`;\n' 'CREATE TABLE IF NOT EXISTS ',DB,'.`County` ( `CountyID` INT UNSIGNED NOT NULL...

mysqli->prepare function returns null

This is a terrible question because I don't have a simple way to reproduce it. However, I'm using the Zend Framework to connect to my MySQL database on OS X. Sometimes a call to the prepare function on a mysqli object returns null. The stated return values for the prepare function are false or a statement object. I can't figure out w...

Which approach is better performance-wise? (with regard to the usage of variable parameter markers in prepared statement in JDBC)

My objective is to get the DeptNames of certain employees from the Emp table. But the number of employees is varying. Please tell if the below approach is correct and which of the below approach is better performance wise. Or is there a better way to go about it? PreparedStatement pstmt = conn.prepareStatement("SELECT Dept from Emp WHER...

Is it possible to use GROUP BY with bind variables?

I want to issue a query like the following select max(col1), f(:1, col2) from t group by f(:1, col2) where :1 is a bind variable. Using PreparedStatement, if I say connection.prepareStatement ("select max(col1), f(?, col2) from t group by f(?, col2)") I get an error from the DBMS complaining that f(?, col2) is not a GROUP BY exp...

JDBC prepareStatement doesn't work

I'm trying to use the prepareStatement function. The code is below. After it executes, it returns me a bunch of string 'vlicense' instead of the the values. When the code finishing the statement.setString(), the statement becomes "select 'vlicense' from Vehicle". However, it needs to be "select vlicense from Vehicle" without the quotatio...

PreparedStatement caching in Tomcat

I am looking for a way to achieve PreparedStatement caching, so as to save recreating the PreparedStatement objects for queries that were already executed in the past. Is there some built in way to achieve this using Tomcat? Or must I program this cache myself? ...

What is a good strategy for caching prepared statements in Tomcat?

Hello, I am looking for a way to cache prepared statements in a servlet environment (specifically, Tomcat 5.5). This is meant to reduce the number of times that prepared statements are created, i.e. the number of times that connection.prepareStatement(sql) is called. My initial idea was to store PreparedStatement objects in the session...

Why do I get this function call error on an non-object when I am calling a function on an object?

Error: Fatal error: Call to a member function bind_param() on a non-object in /var/www/web55/web/pdftest/events.php on line 76 Code: public function countDaysWithoutEvents(){ $sql = "SELECT 7 - COUNT(*) AS NumDaysWithoutEvents FROM (SELECT d.date FROM cali_events e LEFT JOIN cali_dates d ON e.event_...

Why do I need a connection to create PreparedStatements ?

I would like to use prepared statements, for many reasons. But, I would like to create a method that looks like this: /* This opens a connection, executes the query, and closes the connection */ public static void executeNonQuery(String queryString); In other words, I want my application logic to only have to formulate the queries and...

Mysql Prepare statement take column value in variable

Hi All, can anyone give me any idea about how to take column value into a variable. FOR EXAMPLE - Declare TD int; Declare Cnew Varchar(10); SET @a = Concat('Select Count(*) into ', TD, 'From tb1 Where C1 =', Cnew, ';'); how to take the count(*) into TD???? Thanks in advance. ...

How does a leftjoin work while using a initialized prepared statement for MySQLI?

The user comes to this page from a different page where they click on a link and it is appended with a ?photo_id= and then the id number. I want certain information to be available to the viewer when they arrive at this page. I want them to be able to see the photo, the photo name, and the photographers name. The first two are not a pro...

How do I update multiple tables using prepared statements with mySQLi?

I have a form with two fields with the name attribute of 'photo_title' and 'photographer_name', and a hidden field named 'photo_id'. When the user pushes the submit button, i want it to update two separate tables in the database. I can get it to update a single table, but as soon as I try to leftjoin the second table, it doesn't like it....

How can I put the results of a MySQLi prepared statement into an associative array?

I have a sql query and a mysqli prepared statement: $sql = 'SELECT photographers.photographer_id, photographers.photographer_name FROM photographers'; $stmt = $conn->stmt_init(); if ($stmt->prepare($sql)) { $stmt->bind_result($photographer_id, $photographer_name); $OK = $stmt->execute(); $stmt->fetch(); } How can...

How can I set the IDENTITY_INSERT option for a JDBC PreparedStatement?

I need to copy data into an MSSQLServer 2005 database table which has an identity column. I've seen how to disable the identity column by executing SET IDENTITY_INSERT <table> ON before the insert queries. How can I do this when I'm using PreparedStatements to do batch inserts and I can't change the statement during the operation? ...

How can I determine mySQL prepared statement result column names in PHP?

That is, with a prepared statement like: select col1,...coln from table where col3 = ? I believe I can use $mysqli->field_count to get the number of columns being returned (haven't tried). But is there a way to link each column name to the values returned in bind_results? I could always try to parse the column names out from the comm...

Reusing a PreparedStatement

I ran findbugs on our code base and it pointed out there are two more Statements that still need to be closed. In this section of the code we run: preparedStatement = connection.prepareStatement(query); for 3 different queries, reusing preparedStatement. In the finally block we do close the resource: finally{ try{ if (resu...

Prepared Statement not returning anything

Hi all, Please forgive me for the possibility of the stupidity of this question, but I've just started using prepared statements. I know this particular query works, as I tested it with unprepared, procedural methods. Here it is: $name = 'introduction'; $mysqli = new mysqli('localhost', 'user', 'pass', 'db') or die('There was a probl...

Postgresql: using 'NULL' value when insert and update rows with prepared statements

Hi guys, sometimes i need to insert into the table some null values, or update them setting the value to NULL. I've read somewhere in the postgresql documentation that this cant be done, but can be tricket with the default value: pg_query("INSERT INTO my_table (col_a, col_b) VALUES ('whatever', default) p.s: i know that in this examp...

Problem with preparedStatement

Excerpt from code PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM sch.tab1 where col1 like lower ( 'ABZ' ) "); preparedStatement.executeQuery(); The above code executes successfully. But when i try to execute this PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM sch....