pdo

PHP/PDO - Flush privileges

Hi, I'm doing some mysql server management with a script that flushes the MySQL users privileges when new privileges are added to a MySQL user. I'm using the PDO class to do my queries, but when I do a simple FLUSH PRIVILEGES; I get, for $connection->exec('FLUSH PRIVILEGES;'); and $connection->query('FLUSH PRIVILEGES;'); S...

In PHP, when using PDO with pgSQL how to get the value of "RETURNING" clause in the original INSERT sql query.

In PHP, I am using PDO with the pgSQL drivers. I wanted to know how to get the value of the "RETURNING" clause given in the INSERT sql query. My current code looks like this, $query = 'INSERT INTO "TEST" (firstname, lastname) VALUES ('John', 'Doe') RETURNING user_id'; $queryHandle = $connection->prepare($query); $queryHandle->execute();...

PDO: check tags presence in db and then insert

Hi, I'm working with PDO connection for mysql and I'd like to have some opinion on a query I use to check if tags are present on the database, and to add it in the case it isn't. // the tags are allready processed in $tags array $check_stmt = $connection->prepare ("SELECT * FROM tags WHERE tag_name = :tag_name"); $save_stmt = $connect...

Zend_Db/PDO Testing for the Table Storage Engine

Brief background - Im writing a special import manager to be run via cron. The basic operation is: Delete all records from table Load data from a file or a string into the table Not to difficult, however because of the apocolyptic delete at the beginning of this sequence id like to use a transaction so i can rollback if anything goes...

Invalid parameter number: number of bound variables does not match number of tokens

I have a table: 'objects' with few columns: object_id:int, object_type:int, object_status:int, object_lati:float, object_long:float My query is : $stmt = $db->query('SELECT o.object_id, o.object_type, o.object_status, o.object_lati, o.object_long FROM objects o WHERE o.object_id = 1'); $res = $stmt->fetch(); Pdo throw error: SQLSTATE[...

When should I use transactions in my queries?

Hi, I'm reading on web, very detailed tutorials on how to use transactions with database types and database engines, but I haven't found some guide that teach me when and why I should use them. I know transactions are usually used for home bankings, so when we work with money data, but I can immagine they are used in many other ways. T...

PDO::MYSQL_ATTR_USE_BUFFERED_QUERY and multiple delete statements in prepared statement

I am trying to use a prepared statement that deletes from two (temporary) tables: public function clearTempTables() { static $delStmt = null; if (null == $delStmt) { $delStmt = $this->pdo->prepare("DELETE FROM product_string_ids; DELETE FROM product_dimension_valu...

pass PDO bindParam type in array

I am trying to pass the parameter constraint to PDO from an array i.e. public function write($sql,$bindparams=''){ try{ $stmt = $this->db_connection->prepare($sql); if($bindparams != '' && is_array($bindparams)){ foreach($bindparams as $k){ $b = $k[0]; //parameter to bind to ...

ADODB to PDO quick switch

Hi! In past i use adodb for mysql in php. Now i wont to use PDO. How can i quick switch from adodb query to pdo using one connection to datebase? ...

Pgpool, ZendFramework, PDO

have 2 computers with 2 db Postgresql PHP with PDO Work with pgpool Often times i recive error ERROR: pgpool detected difference of the number of inserted, updated or deleted tuples. OR Error that connection is out Without pgpool all work. May be some one know where is a problem. ...

What is difference between mysql,mysqli and pdo ?

What is difference between mysql,mysqli and pdo ? Which one is the best suited to use with PHP-MYSQL? ...

¿How to bind params to an statement using a loop?

Hi! I'm just learning to use PDO, and I want to bind params to a delete statement using a loop. I'm using a code like this that definitely doesn't works: public function delete_user ($post, $table='mytable') { $delete = $this->conn->prepare("DELETE FROM $table WHERE id IN (:id) "); ...

Using PDO to create a mysql query function, wont insert rows

Trying to get a grasp of using PDO, and I'm using some pre-made functions to make things simpler for when I want to do a query. First one connects, second runs the query. Unfortunately it won't let me INSERT rows using dbquery(). SELECT works fine, just can't seem to get anything else to work. Here's the code: function dbConnect() ...

Safely using prepared statements to query database

I'm trying to write a function that is versatile in the queries it is allowed to make, but also safe from injection. The code below throws an error as is, but if I run it with 'name' instead of ':field' it works fine. $field = "name"; $value = "joe"; function selectquery($field, $value) { global $dbcon; $select = $dbcon->prepare...

PHP prepared statement: Why is this throwing a fatal error?

Have no idea whats going wrong here. Keeps throwing... Fatal error: Call to a member function prepare() on a non-object ...every time it gets to the $select = $dbcon->prepare('SELECT * FROM tester1');part. Can somebody shed some light as to what I'm doing wrong? function selectall() //returns array $client[][]. first br...

Is there a built in way to get an array out of multi dim array in PHP?

(Very useful when querying DB). If I have a multy dim array [['id'=>1],['id'=>2],['id'=>34],['id'=>67]] and what I want is [1,2,34,67] I know how to do it in code, just asking if there is a built in way in PHP (or may be in PDO) to do this. ...

How to change from mysql to pdo using prepared statements in PHP?

$dml = "insert into bookmark(accountId,category,url,hash,title,created) value($_SESSION[accountId],$_POST[category],'$_POST[url]',md5('$_POST[url]'),'$_POST[title]',now())"; mysql_query($dml,$con); How do I do this statement using prepared statements in PDO? ...

When is quoting necessary in prepared statements of pdo in PHP?

It's from the comment under this answer,but I really don't figure out what he means: http://stackoverflow.com/questions/2211919/how-to-change-from-mysql-to-pdo-using-prepared-statements-in-php/2211992#2211992 ...

String encoding problem on PdoStatement->bindParam()?

Hi, I'm trying to perform a simple SELECT statement from a string taken from a $_REQUEST var but it seem my PDO statement doesn't like the string format, why? My $_REQUEST var contains a string like Hello+World, so I need to replace + with whitespaces to do my SELECT statement correctly. // the data returned is Hello+World $phrase = st...

Should I use prepared statements for MySQL in PHP PERFORMANCE-WISE?

I understand the security benefits of prepared statements in MySQL. No need to cover that topic here. I'm wondering about the performance aspect of them. Now, I know when a query using a prepared statement is executed twice in a single PHP script, it's faster because the query is only parsed once, once for each query. The client makes o...