pdo

Check if a database table exists using php/pdo

Hi, I want to check if a table with a specific name exists in a database i've connected to using php and pdo. It has to work on all database backends ... MySQL, SQLite, ... best regards, andre ...

pdo database abstraction

Hello, Can someone help me to see what is going wrong with this setup I build the @sql query in the function below like this. The extra quotes are setup in the conditions array. $sql .= " WHERE $field = \"$value\""; The pdo update function loops the conditions array like this. if (!is_null($conditions)) { $cond = ' WHERE'; $ob...

Precision loss whilst inserting a double into MySQL through PDO

Hi All, I've run into this really annoying behavior and I want to know if I'm doing something wrong, or if this is intentional (and if so, why). Whenever I have a variable in php (5.3) that is of type double and I want to insert it into the database (MYSQL 5.0) in a field that is of type double, the value always gets rounded down to 6 ...

Why is PDO better for escaping MySQL queries/querystrings than mysql_real_escape_string?

I've been told that I'd be better using PDO for MySQL escaping, rather than mysql_real_escape_string. Maybe I'm having a brain-dead day (or it may be the fact I'm by no stretch of the imagination a natural programmer, and I'm still very much at the newbie stage when it comes to PHP), but having checked out the PHP manual and read the en...

retrieval of user-supplied data: any benefit for prepared statements

Prepared statements are good to prevent sql injection when the user supplies data and we use that data for db insertion or just even to structure the query. But is really any benefit to PDO when I'm retrieving previously-inserted user-supplied data from the database? It sounds to me like the answer is no. It's already in. As long as th...

PHP: Injection protection using prepared statements

Hi, I am familiar with using PHP to perform mySQL queries. However, I have been using reg exps as protection against injection attacks. After reading several questions/answers here on SO, I've decided to opt for prepared statements instead. There's two options available (let me know if there are more): mysqli prepared statements PDO ...

In PHP with PDO, how to check the final SQL parametrized query?

Hello, In PHP, when accessing MySQL database with PDO with parametrized query, how can you check the final query (after having replaced all tokens)? Is there a way to check what gets really executed by the database? ...

PHP PDO prepared statement -- mysql LIKE query

Hello All, This is my first post to stack Overflow, but I find the existing body of knowledge very helpful. At any rate, here's my issue: I am trying to do a search through php's PDO class (mysql driver). I have the following query working with the mysql client (table names changed to protect the innocent): SELECT hs.hs_pk, ...

PHP: Mixing old mysql with PDO

I'm writing an application which makes use of some legacy code. The newer code uses PDO, while the older uses the original mysql library. A large amount of data is input in a transaction in the first code, so that I can roll back on error, but the legacy code is called at some points and needs to see the same data; unless the connectio...

I get 2014 Cannot execute queries while other unbuffered queries are active when doing exec with PDO

I am doing a PDO::exec command on multiple updates: $MyPdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,true); $MyPdo->exec("update t1 set f1=1;update t2 set f1=2"); I am doing it inside a transaction, and I keep getting: SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active....

PHP PDO MYSQL JOIN

I have a table called cms_page in which each page has an ID. I want to pull all the information from this table and all the information from cms_page_part table where page_id is equal to the ID i send to the page...confusing i know but here is my attempt: require '../../config.php'; $conn = new PDO(DB_DSN, DB_USER, DB_PASS); $id = (in...

two dimensional array PHP PDO

Could anyone help with this please? I am pulling the results in below from the cms_page_part table. I know for a fact there should be two rows. One where "name" is equal to "body" and the other that exists is "testionial" however my query below only prints the first one. Is it because im fetching the results incorrectly? <div class=...

Error when connecting to MySQL using PHP/PDO

My code was working all fine yesterday and today it suddenly just don't want to connect to my database. I have changed no settings on it or on the code and I haven't updated any software either. All I do is this: new PDO('mysql:host=localhost;port=3306;dbname=test', 'username', 'password'); And I get a nice exception message saying t...

How to bind in PDO a string with %

I have the following query, (which don't work). How do I bid strings inside an existing string with % (I believe the % is not the problem, but really not sure). $sql="SELECT * FROM T WHERE f LIKE '%:bindParamString%'"; ...

Does PDO still use binary transfer with prepared statement bound params?

One of the benefits of prepared statements, (really the only major one) is that SQL commands/triggers are sent in one request - and the user-data (or whatever you provide) is sent in another transfer. This transfer of the user-data (i.e. for an INSERT) is supposed to be in binary form so that PHP (and then the DB server) don't waste time...

pdo Invalid parameter number

Hello, My problem is the following Y have two functions that are called from inside a function(method) If the outcome of the first function is TRUE, the second function runs a select and an update query. The second function runs a select with the query($sql) command The update query uses: $stmt = $db->prepare($sql); $stmt->execut...

php 5.3.1 and PDO

I am getting PDO::__construct(): OK packet 6 bytes shorter than expected in latest PHP 5.3.1, any idea or fixes? ...

PDO and PDOStatement, magical assignments

Hi there, I have the following "test-class" made on the fly: http://sumoin.pastebin.com/ff744ea4 No fine-tuning or something else, just a brief testing pdo class. And I have the test.php: http://sumoin.pastebin.com/d70dcb4ec The funny thing is: The PDOStatement object is never returned directly and I it never gets assigned to $this->...

PHP PDO Caching

Hi there, I've been looking for an answer to this but haven't found it anywhere. Are calls to PDO::prepare() cached, or should I cache the result myself, i.e. if I do the following function foo () { $handle = PDO::prepare(...); /* do stuff with the handle */ } will the prepare() statement be cached by PDO so that it's quickly re...

Creating new SQLite DBs with PDO

I want to provide a setup feature in my next project and I'm wondering if it's possible to create a SQLite 3 database from scratch with PDO or I'm just stuck at connecting to existing databases via DSN? If it isn't possible with PDO is there any way to create a new DB via PHP? ...