pdo

Is it better to use a prepared Select statement when you are only doing one select?

I am currently writing a CRUD class in PHP using PDO. I like the security that prepared statements provide, but I have heard that they also prevent databases like mysql from using the queryCache. Is it better to use a prepared Select statement when you are only doing one select at a time? or would just $pdo->quote() suffice the securit...

mysql_data_seek pdo equivalent

Hi, Which is the equivalent of mysql_data_seek using pdo objects? Can you give me an example? Thanks! ...

When and How to use Multiple MySQL Queries with PHP (PDO)

What are the benefits of using multiple MySQL queries in a statement, other than to minimize code. How do you execute, retrieve, and display the results of multiple MySQL queries sent in one statement using PHP (and preferably PDO). ...

Troubleshooting PDO: Error not caught when executing prepared statement

I have run into a problem using pdo because an error was not caught. The code is simple and works just fine, I´ll just include a sample to avoid confusion: $sql = 'INSERT INTO somedatetable (something) VALUES (:something) ON DUPLICATE KEY UPDATE something=:something' try { $stmt = $dbh->prepare($sql); $values = ...

Associative arrays and binding parameters

I've gotten a little confused with the PDO::prepare functions. I have something like this array('user_email'=>'[email protected]','user_pass'=>'password') and i'd like to translate it into something like this INSERT INTO user_info (user_email, user_pass) VALUES ([email protected], password) using parameterized queries with PDO (or mysqli,...

Possible PDOException Errors (MySQL 5)?

So I'm setting up an installer for my web app, and have input fields for database credentials. Part of my validation process includes testing the database connection (using PHP's PDO library). If the connection fails, I want to be able to differentiate between a bad password, bad address, nonexistent database name, etc. so I can referenc...

How can I simply return objects in PDO?

Trying out PDO for the first time. $dbh = new PDO("mysql:host=$hostname;dbname=animals", $username, $password); $stmt = $dbh->query("SELECT * FROM animals"); $stmt->setFetchMode(PDO::FETCH_INTO, new animals); foreach($stmt as $animals) { echo $animals->name; } If i skip the setFetchMode() method, then I need to call $animals["na...

User defined MySQL function not accessible with PHP PDO connection

I've got a trivial MySQL function: DELIMITER $$ DROP FUNCTION IF EXISTS `mydb`.`CALC` $$ CREATE FUNCTION `mydb`.`CALC_IT`(Flag VARCHAR(1), One FLOAT, Other FLOAT) RETURNS FLOAT BEGIN IF One IS NULL THEN RETURN 0; END IF; IF Other IS NULL THEN RETURN 0; END IF; IF Flag = 'Y' THEN RETURN Other - One; ELSE ...

How can I properly use a PDO object for a Select query

I've tried following the PHP.net instructions for doing Select queries but I am not sure the best way to go about doing this. I would like to use a parameterized Select query, if possible, to return the ID in a table where the name field matches the parameter. This should return one ID because it will be unique. I would then like to us...

PDO's rowCount() Not Working on PHP 5.2.6+

So I've been using PHP's PDO as my database goto class for a while now, unfortunately today after debugging for a while on a client's server (with PHP 5.2.6 installed) I discover this. We tried upgrading to the newest stable release (5.2.9) but the problem persists. Has anyone found a workaround? ...

Moving from mysql to mysqli or pdo?

Duplicate: mysqli or PDO - what are the pros and cons? I'm looking to move a website from mysql to either mysqli or pdo as primarily a learning tool, but also for performance increases if possible. I have read through http://php.net/manual/en/mysqli.overview.php and it seems like both would suit my needs, but it doesn't lean stro...

PHP's PDO Prepare Method Fails While in a Loop

Given the following code: // Connect to MySQL up here $example_query = $database->prepare('SELECT * FROM table2'); if ($example_query === false) die('prepare failed'); $query = $database->prepare('SELECT * FROM table1'); $query->execute(); while ($results = $query->fetch()) { $example_query = $database->prepare('SELECT * FROM tabl...

Connect to SQL Server 2008 with PDO

I am trying to connect to SQL Server 2008 (not express) with PHP 5.2.9-2 on Windows XP sp2. I can connect to the remote SQL Server fine from SQL Server Management Studio from the same machine. My first attempt was this: $conn = new PDO("mssql:host={$host};dbname={$db}", $user, $pass); Which gives this error: PHP Fatal error: Unc...

php pdo ¿What am I doing wrong?

I'm learning php pdo; my environment is : NetBeans 6.5.1, XAMPP 1.7.0 and I have this code, which it seems to connect. If I change dbname to a non existent one, it raises exception "db not exists" If I change user, it raises "login incorrect") but when I call $cn->query, it raises: An unhandled Win32 exception occurred in apache...

Php PDO::bindParam data types.. how does it work?

Hi guys, im wondering what the declaration of the data type in the bind parameter (or value) is used for... I mean, i thougth that if i define a param like int, PDO::PARAM_INT, the param must be converted in int, something like $delete->bindParam(1, $kill, PDO::PARAM_INT); //should works like $delete->bindParam(1, (int)$kill); or at ...

PDO Unbuffered queries

Hello guys, I'm trying to get into PDO details. So I coded this: $cn = getConnection(); // get table sequence $comando = "call p_generate_seq('bitacora')"; $id = getValue($cn, $comando); //$comando = 'INSERT INTO dsa_bitacora (id, estado, fch_creacion) VALUES (?, ?, ?)'; $comando = 'INSERT INTO dsa_bitacora (id, estado, fch_creacion)...

PHP PDO Connection to SQL Server with integrated security?

Can I connect to SQL Server 2008 using PDO and integrated security using the mssql driver? Currently doing something like this to connect normally: $db = new PDO("mssql:host=host;dbname=db", "user", "pass"); This works fine using SQL Server authentication, but it is a pain having to create SQL server logins for loads of databases, so ...

mysql vs PDO

Hello, I'm fairly new to php and have built a medium sized website using standard mysql database calls. However, I have recently learned about PDO and I am hoping to find out from the community if it is worth switching from mysql over to PDO. For security I have been using mysql_real_escape_string. Info about the site: I'm using a m...

Cant the prepared statement be used throught the transaction, from php?

Hi again, guys. I work on a LAPP environment (linux apache postgresql php), and i'm just triyn to find out how to use the prepared statement within the transaction (if is possible). I hope code will explain better then words: Example 1, simple transaction: BEGIN; INSERT INTO requests (user_id, description, date) VALUES ('4', 'This do...

Installing PDO extension for MySQL on Mac OS X Server

I would like to keep the PHP / MySQL combo as 'stock vanilla' as possible but would like to install the PDO driver for MySQL. How can I do this on 10.5? ...