pdo

Most performant alternative to SELECT COUNT(*) using PDO and MySQL

I've read previously that SELECT COUNT(*) is not performant in MySQL and should be regularly avoided. (As a side question, is this only the case for a large number of rows?) I'm using PHP Data Objects (PDO) to access MySQL. How should I be counting rows with performance considerations in mind? ...

What all fetch modes are there for PDO?

I am just getting started using PDO. I am wondering if there is a list of all the available FETCH_* modes and what each does? I found this page of the manuals that covers setFetchMode which even has this line in it: The fetch mode must be one of the PDO::FETCH_* constants. But I see nothing that lists what all is available? ...

PHP/PDO: Prepared statements don't work when creating a table?

When I am using a PDO prepared statement, and use it to plug in a table name to the query it fails, a quick example: $stmt = $dbh->prepare("CREATE TABLE ? (id foo, int bar,...)"); $stmt->execute(Array('table_foobar')); All it does is replaces ? with 'table_foobar', the single quotes don't allow creation of the table for me! I end up ...

PHP/PDO: style of write many queries on one page?

An example of my scenario is a large setup page for an application, the method I use is for example: //query 1 $stmt = $dbh->prepare("..."); $stmt->execute(); //query 2 $stmt = $dbh->prepare("..."); $stmt->execute(); Would this be an accepted method to write more queries? I have no clue how it's supposed to be done (or who does what,...

PDO: does prepare() escape all data, even if not bound?

Certain data types, I.E. numbers or a table name cannot be added as a parameter with PDO, as it adds single quotes around them. When I add them (the variables) manually, say something like this: $statement = $dbh->prepare("INSERT INTO $TABLE_NAME (id, foo, timestamp) VALUES (1234, ?, 4567890))"); $statement->execute(Array($foo)); ...

php pdo prepare in a function returns

Somehow my execute statement says the object has no member "execute". What is wrong? class EdlSqliteDb { const SQLITE_DRIVER = "sqlite:"; var $dbh; var $qIndex = Array(); // function EdlSqliteDb($dsn) { try { $this->dbh = new PDO(self::SQLITE_DRIVER . $dsn); } catch (PDOException $e) { echo "Erro...

can we give capital letter and underscore in pdo named placeholder.

Hi, Can we give capital letter and underscore in PDO named place holder. Below Is my query: insert into product_pepe (Type_Class, ID_Alias, Sort_order_Position, DaysBeforeReminder, DaysForNxtVaccination, IsSitemapple_IsSitemappable, NoFollowUpVaccinations, NoOfReminders_NoOfReminders, NoVaccinationsInPacket, RRP_RRP, ...

How do I stop MySQL from duplicating every column's entry in returned arrays?

My MySQL queries are returning arrays with duplicate entries: numbered keys and labeled keys with the same data inside. This may be standard, but it seems like a waste, and something that could cause problems if I'm printing values. I mean, not a huge problem, obviously. But I'm just curious if I can stop that. It seems unnecessary. For ...

PHP And PDO preventing Javascript injection

Hey guys I have a site written in PHP utilizing PDO. I am using the bindParam() function to bind to a sql insert query: ("insert into Table (id, date, data) VALUES (?, ?, ?)") but I am able to insert a string containing "<script>window.location="google.com"</script>" How to prevent this? Thanks!!! ...

PHP Singleton PDO

from http://www.php.net/manual/en/class.pdo.php ###### config.ini ###### db_driver=mysql db_user=root db_password=924892xp [dsn] host=localhost port=3306 dbname=localhost [db_options] PDO::MYSQL_ATTR_INIT_COMMAND=set names utf8 [db_attributes] ATTR_ERRMODE=ERRMODE_EXCEPTION ############ <?php class Database { private static $lin...

Call to undefined method Database::prepare()

from http://www.php.net/manual/en/class.pdo.php ###### config.ini ###### db_driver=mysql db_user=root db_password=924892xp [dsn] host=localhost port=3306 dbname=localhost [db_options] PDO::MYSQL_ATTR_INIT_COMMAND=set names utf8 [db_attributes] ATTR_ERRMODE=ERRMODE_EXCEPTION ############ <?php class Database { private static $lin...

Method for Using PDO in PHP

So I've found a method which looked nice to me: http://www.php.net/manual/en/class.pdo.php#97682 Requires PHP 5.3 but my host only supports 5.2 :( So what method should I use for PDO, where it only connects to the database when needed? And reuses the same connection? ...

How to check if there are results with Prepared Statements...

Hi there, In the past I would do something like so: $sql = 'SELECT * FROM customers WHERE customer_email="' . mysql_real_escape_string($_POST['customer_email']) . '" '; $res = mysql_query($sql); // if there are no hits... if(mysql_num_rows($res) == FALSE) { Today I am doing the same thing however with prepared statements: ...

how do i enable pdo extenstion in my hosting provider

1) My whole application is built on PDO with sqlite My Problem: The hosting provider has PDO --disabled I want to know how i can get PDO extensions to work on my hosting provider. The hosting provider just doesnt seem to respond to my queries. So is there any way i can do this remotely. ...

PDO->bindParam, PDO->bindValue and PDO->closeCursor

So far I have been using PDO->bindParam however while reading the manual I found PDO->bindValue from what I can tell PDO->bindValue passes by value where as PDO->bindParam passes by reference, is this the only difference? $modThread = db()->prepare("UPDATE `threads` SET `modtime` = UNIX_TIMESTAMP( ) WHERE `threadid` =:id LIMIT 1"); whi...

fetchAll helper function using PDO

Suppose I have a function function fetchAll(){ $args = func_get_args(); $query = array_shift($args); $query = str_replace("%s","'%s'",$query); foreach ($args as $key => $val) { $args[$key] = mysql_real_escape_string($val); } $query = vsprintf($query, $args); if (!$query) return FALSE; $res = mysql_query($query); ...

How to squeeze error message out of PDO?

I can't seem to get any error message from PDO #$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING ); try { $sth = $dbh->prepare('@$%T$!!!'); print_r($sth); print_r($dbh->errorInfo()); } catch (PDOException $e) { echo $e->getMessage(); } giving out only PDOStatement Object ( [queryString] => @$%T$!!! ) Array ( ...

The way PDO parametrized query works

PLEASE READ THE QUESTION CAREFULLY. It is not usual silly "my code doesn't work!!!" question. When I run this code with intended error try { $sth = $dbh->prepare("SELECT id FROM users WHERE name INN(?,?) "); $sth->execute(array("I'm","d'Artagnan")); } catch (PDOException $e) { echo $e->getMessage(); } I get this error me...

Stop Zend_Db from quoting Sybase BIT datatype field values

I'm using Pdo_Mssql adapter against a Sybase database and working around issues encountered. One pesky issue remaining is Zend_Db's instance on quoting BIT field values. When running the following for an insert: $row = $this->createRow(); ... $row->MyBitField = $data['MyBitField']; ... $row->save(); FreeTDS log output shows: dbutil.c:...

Which PHP extension should I use for my DB wrapper

Hi there! I'm building a database wrapper for my own use and I can't decide which PHP extension I should use, PDO or MySQLi. I'm only planning to use MySQL so I don't care about the support for other adapters with PDO. I've read a lot that PDO is becoming a 'standard' with PHP and perhaps I should use that? Then I think it's 'too much'...