pdo

mysql_? equivalent of PDO's prepare() and execute()

One of my hosting server does not support PDO. Are there and mysql_ commands which does the same function of PDO's prepare() and execute()? I am looking for the parameter substitution feature, i.e. VALUES (?, ?). ...

PHP PDO - When to use bindParam(1, $blabla) versus bindParam(':blabla', $blabla)

All, I don't really understand the usage case for named placeholders bindParam(':blabla', $blabla) versus numbered placeholders bindParam(1, $blabla). Is it mostly a question of readability? Thanks, JDelage ...

PDO, mysql, transactions and table locking

For fun I am replacing the mysqli extension in my app with PDO. Once in awhile I need to use transactions + table locking. In these situations, according to the mysql manual, the syntax needs to be a bit different. Instead of calling START TRANSACTION, you do it like so... SET autocommit=0; LOCK TABLES t1 WRITE, t2 READ, ...; ... do ...

PDO positional and named parameters as part of the same prepared query?

I'm learning the ropes with PDO. Here is my sql (the number of parameters that can appear in the WHERE is variable). SELECT ID, title FROM table WHERE something = ? ORDER BY :sort :dir LIMIT :start, :results Here is my code: $query = $conn->prepare($sql); ...

Change the return format on PHP's PDO Select

I am writing my own PDO wrapper to make my life easier and a fair amount safer. A standard query looks like: $user = $db->select('users') ->eq('twitter_id', $twitter_id) ->limit(1) ->prepare() ->exec(); Generates this query: SELECT * FROM users WHERE twitter_id = :twitter_id LIMIT 1 This...

php code to test pdo is available?

I want to use PDO but I'm not sure whether my hosting has set it up properly. How can I test, in PHP, whether it is setup and working for MySQL? ...

PDO Prepared Statement does not UPDATE table

I am developing an ORM based on PDO, for tables that don't have unique ID fields, so when I update or delete, I need to compare to the previous values of the record, and LIMIT 1. When my query finally gets to the database and is executed with the parameters, everything is correct, as confirmed by the general query log, however, nothing ...

How to query many to many

I'm trying to do a many to many query on these fields. I'd like to get: 1) all the posts that are in a category 2) all the categories that are in a post 3) all the posts that are in a category that have a specific id posts +-------------+--------------+ | id | int(11) | | title | varchar(255) | | body |...

Mocking The PDO Object using PHPUnit

I'm having difficulty mocking the PDO object with PHPUnit. There doesn't seem to be much information on the web about my problem but from what I can gather: PDO has 'final' __wakeup and __sleep methods that prevent it from being serialised. PHPunit's mock object implementation serialises the object at some point. The unit tests then...

Do PHP PDO prepared statments need to be escaped?

Hey Everyone, On the PDO::Prepare page it states, "and helps to prevent SQL injection attacks by eliminating the need to manually quote the parameters" Knowing this, is there a PHP function like mysql_real_escape_string() that takes care of escaping stings for PDO? Or does PDO take care of all escaping for me? EDIT I realize now th...

adodb, pdo or other, I want autoExecute

I used to use PEAR MDB2 and one of the things I loved was the autoExecute() It really cut down on code. But's it's a pain having to get MDB2 enabled on some hosted servers. I'd like to use either PDO or just include some class file. It looks like adodb has autoExecute too http://phplens.com/lens/adodb/docs-adodb.htm#autoexecute Is th...

How can I determine the column type with PDO?

Hello folks. I need a way to determine the type of a database column (varchar/numeric/date/...) when reading from the DB with PDO. When fetching values from the DB, PDO produces only string values, regardless of the actual type of the table column. Is there any non driver specific way to get this information? I know that there are SQL...

Saving memory when fetching large result sets with PDO

Hi everybody. I have written a tool for database replication in PHP. It's working fine but there's one issue: I'm using PDO to connect to the different databases to keep it independent of any specific RDBMS, which is crucial to this application. The tool does some analysis on the tables to decide how to convert certain types and some ...

PDO Query not printing anything

I have the following function which enables a query to run with a where condition. But it seems not to be producing any results. I can connect to the database so that is not an issue. Any help would be appreciated. public function executewhereQuery(Array $tableData, $fieldType, $table, $tableField){ $dbh = $this->connect(); ...

PHP Class Database interaction (using PDO)

Hey guys, so I'm completely new to Object Oriented PHP -- I've read some tutorials, but I can't find anything that really goes into working with a database with PHP classes. I'm trying to make something simple -- a quick news post class. You get the post from the database, etc. However, I'm getting an error whenever I try to interact wi...

Why would this SQL error with "Invalid use of group function"?

This is a simple query ran when the user presses logout from my website UPDATE `user_logins` SET `active` = 0 WHERE `user_id` = 3 AND `datetime` = MAX(`datetime`) LIMIT 1 The user_id value is binded in there with PDO. I get the following exception thrown Invalid use of group function Googling around seems to say that ...

Selecting rows from a table based on results from other tables in Mysql and PDO

Hi, I'm kind of stumped. I have a table of items with fields: ID, title, created_by, group. I also have another table of groups with fields: ID, created_by, group_name and a final table of users with fields: ID, username, password etc. The idea is that only items created by the logged in user or items where the logged in user i...

using doctrine 2 with SQL Server

I need to migrate an existing project, built on the current beta of doctrine 2, from mysql to SQL Server. I have complete control of the SQL Server. In the DBAL Folder of Doctrine there already is a PDOMsSql driver, but I can't figure out, how to use it. (there is still no documentation) Doctrine also offers two other ways, I could ma...

PHP PDO fetch returns a array ?

$GetUid = $dbConnect->prepare("SELECT UID FROM users WHERE username = :username"); $GetUid->execute($RegisterData3); $UserID = $GetUid->fetch(); why does it return array not a string ? var_dump('$UserID') says array 'UID' => string '45' (length=2) 0 => string '45' (length=2) it should be array 'UID' => string '45' (length=2)...

I have a problem connecting to my db on godaddy with PDO

I have been trying to connect to my database using pdo on godaddy with no successs. Initially i got the error: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) Then i look around the web, found out that i need to change the part to socket. I looked for my socket found it and ch...