codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
<?php // What is the new data for Steve's record? $FirstName = 'Steven'; $LastName = 'Ollinger'; $Username = 'ollinger'; // What record are we updating? $id = 6; // 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 = "update users set vcFirstName=?,vcLastName=?,vcUsername=? where intID_pk=?"; // Prepare the statement $query = $db->prepare($sql); // Execute the statement $query->execute(array($FirstName,$LastName,$Username,$id)); // 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