codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
<?php // Create a DSN for MySQL (Syntax: 'mysql:host=[server];dbname=[database]') $MySQLDSN = 'mysql:host=localhost;dbname=TestDatabase'; try { // Create a new (MySQL) PDO object (Syntax: 'PDO([DSN], [UserName], [Password]') $db = new PDO($MySQLDSN, 'TestUser', 'TestPassword'); // What is your intended query? $sql = 'select * from users'; // Store the result of the query in a variable $result = $db->query($sql); // Store any resulting errors $errorInfo = $db->errorInfo(); // If there were any errors, assign them to the error variables if (isset($errorInfo[2])){ $error = $errorInfo[2]; } } catch (PDOException $e) { // Catch any PDO exceptions $error = $e->getMessage(); } // Did an error occur during the above operation? if (isset($error)) { // Display the error echo $error; } else { // Indicate that all went well echo 'OK'; } ?>
Private
[
?
]
Run code
Submit