pdo

Can I use ALTER DATABASE to rename a mysql database?

I am using PDO with PHP to create a new database and then a new user with privileges on that database. In case one of them fails, I want to rename the database and user so that they can be deleted later and the names are available. Is it possible to rename a mysql database using the ALTER DATABASE? ...

SQL group results as a column array

Hi guys, this is an SQL question and don't know which type of JOIN, GROUP BY etc. to use, it is for a chat program where messages are related to rooms and each day in a room is linked to a transcript etc. Basically, when outputting my transcripts, I need to show which users have chatted on that transcript. At the moment I link them thro...

How do I do CRUD jobs using pdo?

Where is a hello world example that has all CRUD operations included? ...

Which is the correct way to use PDO in PHP?

One from here: $sth->execute(array(':calories' => $calories, ':colour' => $colour)); The other from here: /*** reassign the variables again ***/ $data = array('animal_id'=>4, 'animal_name' => 'bruce'); /*** execute the prepared statement ***/ $stmt->execute($data); My question is: :key or key ? Sorry I don't have the PHP environm...

PDO lastInsertId issues, php

Hi Guys, I have tried lots of ways to get the last inserted ID with the code below (snipplet from larger class) and now I have given up. Does anyone know howto get PDO lastInsertId to work? Thanks in advance. $sql = "INSERT INTO auth (surname, forename, email, mobile, mobilepin, actlink, regdate) VALUES (:surname, :forename, :ema...

PDO and SQL IN statements

Im using a sequel for search like this using PDOs $states = "'SC','SD'"; $sql = "select * from mytable where states in (:states)"; $params = array(':states'=>$states); and I use my function $result = $this->selectArrayAssoc($sql, $params); where my selectArrayAssoc function as following public function selectArrayAssoc($sql, $params...

PDO:sqlite doesnt INSERT data, yet no error

. try { $res = $db->exec($sql); if ($res === FALSE) { print_r($db->errorInfo()); die(); } } catch(PDOException $e) { die($e->getCode().':'.$e->getMessage()); } catch(Exception $e) { die($e->getCode().':'.$e->getMessage()); } No error info, and neither does it get caught as an exception. Yet ...

How do I use pdo's prepared statement for order by and limit clauses(or can I?If not,what should I reference for a complete list of clauses where parameters can be used) ?

$sql = "SELECT * FROM table ORDER BY :sort :dir LIMIT :start, :results"; $stmt = $dbh->prepare($sql); $stmt->execute(array( 'sort' => $_GET['sort'], 'dir' => $_GET['dir'], 'start' => $_GET['start'], 'results' => $_GET['results'], ) ); I tried to use prepare to do the job,but $stmt->fetchAll(PDO::FETCH_...

How can I make a singleton wrapper for PDO?

How can I make a singleton of the PDO extention? Extending doesn't work, because I get a fatal error when I try it ... ...

How can I get a iterable resultset from the database using pdo, instead of a large array?

I'm using PDO inside a database abstraction library function query that I've made. I'm using fetchAll(), which if you have a lot of results, is supposed to get memory intensive, so I want to provide an argument to toggle between a fetchAll associative array and a pdo result set that can be iterated over with foreach and requires less me...

PHP PDO - Num Rows

PDO apparently has no means to count the number of rows returned from a select query (mysqli has the num_rows variable). Is there a way to do this, short of using count($results->fetchAll()) ? ...

install pdo sqlite driver

how to install pdo sqlite drivers to enable onserver support ...

PHP PDO bindValue() weird problem

<?php try { $db = new PDO("mysql:host=localhost;dbname=DBNAME", "USER", "PASSWD"); $stmt = $db->prepare("SELECT id, name FROM testdb ORDER BY time DESC LIMIT :index, 10"); $stmt->bindValue(":index", $_GET['index'], PDO::PARAM_INT); $stmt->execute(); while( $r = $stmt->fetch(PDO::FETCH_ASSOC) ) { echo var...

How can I store and access SQLite databases from a central location?

I have installed SQLite on my UNIX system, and am planning on accessing it from PHP. However, the database is created in the directory I initialize it in, and if a script runs in a different directory a new database is created in the same directory. Is there an option for SQLite (or the PHP wrappers) to create the databases in one loc...

Recursion in prepared statements

I've been using PDO and preparing all my statements primarily for security reasons. However, I have a part of my code that does execute the same statement many times with different parameters, and I thought this would be where the prepared statements really shine. But they actually break the code... The basic logic of the code is this. ...

PDO::PARAM for type decimal?

I have 2 database fields `decval` decimal(5,2) `intval` int(3) I have 2 pdo queries that update them. The one that updates the int works ok $update_intval->bindParam(':intval', $intval, PDO::PARAM_INT); but I can't update the decimal field. I've tried the 3 ways below, but nothing works $update_decval->bindParam(':decval', $decval...

mysql PDO how to bind LIKE

In this query select wrd from tablename WHERE wrd LIKE '$partial%' I'm trying to bind the variable '$partial%' with PDO. Not sure how this works with the % at the end. Would it be select wrd from tablename WHERE wrd LIKE ':partial%' where :partial is bound to $partial="somet" or would it be select wrd from tablename WHERE w...

Update query with conditional?

I'm not sure if this possible. If not, let me know. I have a PDO mysql that updates 3 fields. $update = $mypdo->prepare("UPDATE tablename SET field1=:field1, field2=:field2, field3=:field3 WHE...

PDO / Php Problem with LIKE statement and special characters

I've already checked answers to questions like this one (How do I create a PDO parameterized query with a LIKE statement in PHP). I've ended up to this solution: $sql = "SELECT count(*) ". "FROM avs_souscript ". "WHERE num_certif =\"\" ". "AND date_annul=\"\" ". "AND user=:sess_user ". "AND user!...

Need help with nested atomic operations involving PDO transactions

I have two distinct modules that can be used independently, but Module2 is dependent on Module1. Module2 has an operation that needs to be atomic, and it calls an operation in Module1 that also needs be atomic. Assuming I have set PDO::ATTR_ERRMODE to PDO:ERRMODE_EXCEPTION, the following heavily genericised and snipped code yields this...