Created
September 2, 2016 19:47
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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