pdo

pdo_mysql vs mysqli when using Zend_Db

If I am using Zend_Db classes to abstract my queries from the backend database, does it make a difference which mysql driver I use, pdo_mysql vs. mysqli? My understanding of pdo_mysql is it is also to provide abstraction, so I'm assuming that if I am using Zend_Db, then I would not be taking advantage of the extra features as part of mys...

PDO Connection string for SQL Server 2005

What should my PDO constructor/DSN/connection string look like to connect to a SQL Server 2005 database? $dbh = new PDO('??'); ...

Performance in PDO / PHP / MySQL: transaction versus direct execution

I am looping through a number of values (1 to 100 for example) and executing a prepared statement inside the loop. Is there and advantage to using a transaction - committing after the loop ends - compared to a direct execution inside the loop? The values are not dependant on each other so a transaction is not needed from that point of ...

Error on creating connection to PDO in PHP.

Today, I removed and reinstalled the latest version of lampp in order to move to php 5.30, and suddenly a very simple app is failing to connect to the mysql database. I'm using PDO to connect, and receiving the following error: Warning: PDO::__construct() [pdo.--construct]: [2002] Invalid argument (trying to connect via unix://) in /h...

In PHP getting "Class 'PDO' not found" error while trying to connect to Oracle DB.

I am trying to connect to my oracle database using PDO but I am getting Class PDO not found error. I have checked that PDO is enabled and it appears so. Still I am not able to trace why I am getting this error. Here is my configure command, cscript /nologo configure.js "--enable-snapshot-build" "--enable-debug-pack" "--with-snapshot-te...

PDO acts different on two -very- similar queries

The following block of code works fine (no errors) $query = "select * from users where username = ?"; $statement = $sql->prepare($query); echo gettype($statement); // -- This returns 'object' $statement->bindParam(1, $username); The following gives: Fatal error: Call to a member function bindParam() on a non-object in /file.php on lin...

In PHP does the PDO::PDOStatement->bindParam() work as it is expected?

I am trying out PDO in PHP for the first time. I thought that PDOStatement->bindParam() would be a cool way to set the datatypes of the values that i pass in to the sql query. But somehow it doesnt work for me. For example I set the type of a variable to INT in bindParam call. But it still doesnt throw error even when I pass pure string ...

Need help with pdo_mysql and data mapper pattern

I'm having issues with php-cgi.exe crashing while using php-pdo-mysql.dll. I'm using the data mapper design pattern show in Padraic Brady's Zend Off The Deep End and everything has been working correctly. I have a table which stores an ip address whitelist, and I'm able to access that properly via a mapper class using Zend_Db_Table. I...

Equivalent of mysql_list_tables in PHP PDO?

When using PHP PDO to access the database, is there a way to list all the tables in a database? Something like mysql_list_tables() is whats needed. ...

How to get PHP command line to work with PDO?

I want to work with PDO, through PHP command line. It works perfect through the PHP web API, but not through the command line. But when I execute the command: php test.php, it says unknown class PDO. I think it has something to do with the thread-safety difference. Because, when I execute the above command, the following warnings come:...

PHP PDO prepared statements

I was told today that I should really be using PDO and prepared statements in my application. Whilst I understand the benefits, I am struggling to understand how I implement them into my workflow. Aside from the fact that it makes code much cleaner, should I have a specific database class which houses all my prepared statements or should...

PDO - Working with table prefixes

I like to prefix my tables in case I need to install the application to a host with only one database. I was wondering if there is a simple way of working with table prefixes using the PDO class? At the moment, I am having to overwrite each method in my own database wrapped, replace %p with the prefix, and call the super method. It's wo...

Help troubleshooting PDO prepared statement

I've just started learning aboud PDO and prepared statements (which sure seem to beat remembering to use mysql_real_escape_string() every time) but I'm having trouble getting the script to execute properly: <?php error_reporting(E_ALL); echo "start"; try{ $dbh=new PDO('mysql:host=localhost;dbname=DBNAME','USER','PWD'); } catch(PDO...

PDO looping throug and printing fetchAll

I'm having trouble getting my data from fetchAll to print selectively. In normal mysql I do it this way: $rs = mysql_query($sql); while ($row = mysql_fetch_array($rs)){ $id = $row['id']; $n = $row['n']; $k = $row['k']; } In PDO, I'm having trouble. I bound the params, then I'm saving the fetched data into $rs like above, wi...

MySQL check if a table exists without throwing an exception

What is the best way to check if a table exists in MySQL (preferably via PDO in PHP) without throwing an exception. I do not feel like parsing the results of "SHOW TABLES LIKE" et cetera. There must be some sort of boolean query? ...

full-text searching for non-English text in sqlite

How can I make some ful-text searching in non-english texts with sqlite? I use php5.3, with pdo_sqlite. CREATE VIRTUAL TABLE example USING FTS3(title TEXT, TOKENIZE icu hu_HU) This one is dont throw an Exception, but just a 0 byte length .sqlite file has been created. I dont see any virtual table. Below this link, i read that pdo_sqli...

Escaping field names in PDO statements

I am currently building a query where both the field and value parts possibly consist of user inputted data. The problem is escaping the fieldnames. I'm using prepared statements in order to properly escape and quote the values but when escaping the fieldnames i run into trouble. mysql_real_escape_string requires a mysql connection r...

What's the most efficient driver to use with ADODB to access a MySQL5 Database ?

I've been using ADODB for PHP on several projects for quite some time, and I like it for the ease of use and the efficiency. I've never been too curious about the way that lib accesses data because you know...it just worked :) But today I realized I'm still relying on the legacy MySQL4 ADODB drivers. I'm using MySQL 5.x, and it would pr...

Is it possible to check if pdostatement::fetch() has results without iterating through a row?

I have a page which needs to check for results, and the way I came up with to do it is successful, but iterates through the first row of results. Is there a way I can check without iterating, or to go back to that first row without executing the query again? I was doing this: $q = pdo::prepare($SQL); $q->execute(array(':foo'=> foo, '...

PHP: SQL Prepared statement transaction not working correctly. It's inserting 1 SQL statement, not both.

I'm finding that the PDO Transaction is only commiting 1 of my 2 SQL statement. For some reason, my PHP script is not inserting into my MySQL database 'homes' table BUT it does insert into the 'invoices' table - even though I'm using a PHP PDO database transaction. Code below: $conn_str = DB . ':host=' . DB_HOST . ';dbname=' . DB_NAME;...