Skip to content

Instantly share code, notes, and snippets.

@phpdave
Created September 2, 2016 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phpdave/571aaa1cedfbe6db07923fac8897aa61 to your computer and use it in GitHub Desktop.
Save phpdave/571aaa1cedfbe6db07923fac8897aa61 to your computer and use it in GitHub Desktop.
Simple Example of making a PDO ODBC connection to an IBM i and running prepared statements
<?php
$hostname = "MYIBMI";
$user = "MYPROFILE";
$password = "";//leave blank and prompt. (works in windows not sure if it will work in other situations)
$pdoConnection = new PDO("odbc:" . $hostname, $user, $password);
$sql="SELECT * FROM MYLIB.MYTABLE WHERE NAME=:NAME AND CITY=:CITY";
$stmt = $pdoConnection->prepare($sql);
if (!$stmt)
{
echo implode($this->_pdoConnection->errorInfo());
}
else
{
$stmt->bindValue(":NAME", "Chuck");
$stmt->bindValue(":CITY", "Orlando");
}
if ($stmt->execute())
{
while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
var_dump($row).PHP_EOL;
}
}
else
{
echo 'statement failed with '.$stmt->errorInfo();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment