Skip to content

Instantly share code, notes, and snippets.

@uu59
Created September 27, 2011 01:46
Show Gist options
  • Save uu59/1244083 to your computer and use it in GitHub Desktop.
Save uu59/1244083 to your computer and use it in GitHub Desktop.
<?php
// mysql Ver 14.14 Distrib 5.1.54, for debian-linux-gnu (x86_64) using readline 6.2
// PHP 5.3.5-1ubuntu7.2 with Suhosin-Patch (cli) (built: May 2 2011 23:00:17)
// Copyright (c) 1997-2009 The PHP Group
// Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
$pdo = new PDO("mysql:host=localhost; dbname=foo", "root", "root");
$pdo->exec("DROP TABLE IF EXISTS t");
$pdo->exec("CREATE TABLE t (id INTEGER NOT NULL AUTO_INCREMENT, c INTEGER NOT NULL, PRIMARY KEY(id))");
$pdo->exec("DELETE FROM t");
$pdo->exec("INSERT INTO t (c) VALUES (1), (2), (3), (4)");
$st = $pdo->prepare("SELECT * FROM t");
$st->execute();
var_dump($st->fetchAll());
echo "----------------------------------------\n";
$st = $pdo->prepare("SELECT * FROM t WHERE c=1");
$st->execute();
var_dump($st->fetchAll());
echo "----------------------------------------\n";
$st = $pdo->prepare("SELECT * FROM t WHERE c=?");
$st->execute(array(1));
var_dump($st->fetchAll());
echo "----------------------------------------\n";
// PHP Notice: Array to string conversion in /tmp/a.php on line 31
$st = $pdo->prepare("SELECT * FROM t WHERE c IN (?)");
$st->execute(array(array(1,3)));
var_dump($st->fetchAll());
echo "----------------------------------------\n";
$st = $pdo->prepare("SELECT * FROM t LIMIT ?");
$st->execute(array(1));
var_dump($st->fetchAll()); // nothing
echo "----------------------------------------\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment