pdo

PHP PDO - migrating to CodeIgniter

Does anyone know if there is a viable library for PDO database access for CodeIgniter? I only ask because I am in the process of migrating over to CI and am having trouble integrating my old Database classes as libraries in the CI framework - can't seem to get them to utilize CI's config constants for database access. Any thoughts? It...

Should I be binding individual array entries, or just executing the array with PDO

I have an assoc array filled with the values necessary for a PDOstatement. Should I, bind each value then call execute? Or call execute passing it the array of values? Array( [name] => Joe [value] => some content ) Should I: foreach($data as $key => $value){ $statement->bindValue($key, $value); } execute(); OR execute($data...

empty file problem [solved]

REWROTE: SOLVED Hi there, I currently worked on a simple application with a database, a bunch of controllers, views and a model class. I coded the controllers and inserted the db connections directly E.g. Each controller method has his own PDO to connect to a specific database+table. I refactored this because I had too many active P...

What are the differences between ADOdb and PDO in PHP?

Both seem to try making it simpler using a database in PHP. Both seem to provide an abstraction over different database types like MySQL, SQLite, etc. What are the differences between both ADOdb and PDO? ...

Are there good Tutorials on how to use PDO?

Maybe someone did a tutorial that shows the important thing: Setting everything up and using it with MySQL? ...

How can I see the SQL statements which go to the database when using PDO?

How can I see the SQL statements which go to the database when using PDO? ...

PDO: If my host ist localhost:80, what do I have to put in here?

I got this example from the php site: <?php try { $dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass); foreach($dbh->query('SELECT * from FOO') as $row) { print_r($row); } $dbh = null; } catch (PDOException $e) { print "Error!: " . $e->getMessage() . "<br/>"; die(); } ?> I use MAMP on the m...

How to use prepared statements in this query?

I'm new to PHP and PDO, and I try to use prepared statements here. After 1 hour of trying around I give up. Or my tutorial was just horribly bad. EDIT: This works perfectly without prepared statements: try { $dbh = new PDO('mysql:host=localhost;dbname=test', 'root', 'root'); $prepared = $dbh->prepare('SELECT * from sys_navigat...

Do prepared statements in PDO really increase security?

I wonder if those prepared statements of PDO really increase security, or if they are just a "cheap" text-replace in the query. The point of prepared statements actually is, that whatever gets inserted as parameter, will not be parsed by the DBMS as part of the instructions itself, so a parameter like "'; DROP TABLE foobar;" has no e...

Why do these prepared statements not work?

I use NetBeans 6.8 and have MAMP with this config on my mac: Apache 2.0.63 MySQL 5.1.37 PHP 4.4.9 & 5.2.10 APC 3.0.19 & APC 3.1.2 eAccelerator 0.9.5.3 XCache 1.2.2 phpMyAdmin 2.11.9.5 & phpMyAdmin 3.2.0.1 Zend Optimizer 3.3.3 SQLiteManager 1.2.0 Freetype 2.3.9 t1lib 5.1.2 curl 7.19.5 jpeg 7 libpng-1.2.38 gd 2.0.34 libxml 2.7.3 libxslt 1...

Help With Zend_Db_Stmt

I have a little problem with the Zend_Db_Stmt. This works: $sql = " SELECT * FROM bugs"; $stmt = $this->_getDb()->query($sql); return $stmt->fetchAll(); But I am trying to make sure the PDO gets used to query the database so I tried this: $sql = "SELECT * FROM bugs"; $stmt = new Zend_Db_Statement_Pdo($this...

How does ORM work when using PDO in PHP?

I've heard that PDO can do some ORM. Is it a good idea to stick with that or should I consider some alternatives that use PDO to do ORM? In short, what I want to do: I want to automatically map table fields to instance variables. Getters and Setters are created manually. However, I could also think of making an associative array as ivar...

How to retrieve the id of the last inserted row when using PDO in PHP?

Example: I insert a row into the DB with this, using PHP's built in PDO: $sql = "INSERT INTO mytable (name, ok) VALUES ('john', '1')"; $this->dbh->exec($sql); I need the id of that row. How could I get that? ...

Which PDO methods throw exceptions?

When establishing a new PDO db handler, I've got to wrap everything into a try-catch to prevent an error message that would print all db access data to the user. But how about all the other methods like exec(), for example? Must I wrap all of these into a try-catch block? At which point is the PHP documentation telling that an method th...

What should I do when $dbh->beginTransaction() returns FALSE, and from where can I get more information about what went wrong?

If PDO's beginTransaction() fails, it returns false. What would be the best thing to do here? Here's what I'm about to do: If it returns false, I want to log something to a file. I'm really not sure if array PDO::errorInfo ( void ) is my friend here? Would that contain more information? ...

create instance of two classes together

Hello! Im trying to display two list: one for categories and brand but only the categories are being displayed. And when I remove the code for categories, the brands are being displayed. Is it because it is not possible to create instances of two classes in the same php page? In index.php: <?php $obj = new CategoryList(); if (metho...

How can I retrieve the number of rows deleted with PDO?

Hello everyone, Okay, so I have been using a PDO wrapper for a project I'm working on, and I'm trying to find out whether a DELETE query was successful or not. Here is the code I am using: /** * A pretty straight-forward query to delete a row from the verification * table where user_id is $user_id and code is $code */ $result = $this->...

How do I get the $num_rows variable to work

Everything in my code works but $num_results... Book-O-Rama Search Results Book-O-Rama Search Results //create short variable names $searchtype=$_POST['searchtype']; $searchterm=$_POST['searchterm']; $searchterm=trim($searchterm); if (!$searchtype || !$searchterm) { echo 'You have not enter...

If an PHP PDO transaction fails, must I rollback() explicitely?

I've seen an code example where someone does a $dbh->rollback(); when there occurs an PDOException. I thought the database will rollback automatically in such a case? ...

What differences do I have to take into account if using MySQL Transactions?

I was recently told that I should use transactions in my application as they can help run code quicker and prevent MySQL code from executing before a whole page has loaded (e.g. if someone is just refreshing on my page and the whole page doesn't load, no MySQL calls will start and it reduces load on the server.) I'm wondering if I wante...