Configuring the Connection Mysql

<?php
try
{
$pdo = new PDO('mysql:host=localhost;dbname=ijdb', 'ijdbuser',
'mypassword');
}
catch (PDOException $e)
{
$output = 'Unable to connect to the database server.';
include 'output.html.php';
exit();
}
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

If PHP is unable to connect to your MySQL server, or if the username and password
you provided are incorrect, you’ll instead see a similar screen to that in Figure 4.7.
To make sure your error-handling code is working properly, you might want to
misspell your password intentionally to test it out.

When an exception is caught, the value stored
in that variable is actually another PHP object; in fact, all exceptions are represented
by PHP objects! Like the PDO object we have stored in $pdo, the PDOException object
has properties we can access and methods we can call.
Related Posts:
  • magic_quotes_gpc, magic_quotes_runtime Magic quotes is the name of a PHP feature that automatically quotes inputdata, by using the addslashes() function. Historically, this was used so thatform data could be used directly in SQL queries without any security or qu… Read More
  • Associative Arrays? You can use string values as keys. For example, you might create an arraylike this: $myStuff = array();$myStuff[“name”] = “andy”;$myStuff[“email”] = “andy@fsdsd.ca”;Print $myStuff[“name”]; Associative arrays are different t… Read More
  • What is triggers? A trigger is a database object which is associated with particular database table. Triggers gets called automatically when particular event(INSERT, UPDATE, DELETE) occurs on table. … Read More
  • $_ENV and $_SERVER ? PHP sets several variables for you containing information about the server, the environment, and your visitor's request. These are stored in the superglobal arrays $_ENV and $_SERVER, but their availability depends on whe… Read More
  • PHP? PHP (Hyper text Pre Processor) is a scripting language commonly used for web applications … Read More
  • How get the value of current session id? Session_id() returns the session id for the current session. … Read More
  • php interview questions PHP Interview Questions and Answers Click  this  link   … Read More
  • PHP Classes Classes do not use scope keywords, but you can prevent people from instantiating the class by makingthe __construct() method and the __clone() methods private or protected. The __construct()method is used to create the objec… Read More
  • $_GET , $_POST,$_COOKIE?? $_GET contains any variables provided to a script through the GET method.  $_POST contains any variables provided to a script through the POST method.  $_COOKIE contains any variables provided to a script through a… Read More
  • What is LAMP? LAMP means combination of Linux, Apache, MySQL and PHP. … Read More
  • Web server compression? The best way to understand web server compression is to think of sending ZIP filesinstead of uncompressed files from your web server to your web user. Sending less dataover the network will minimize network latency and your … Read More
  • Checking Variable Values and Types FUNCTION is_numeric() True if number or numeric stringctype_digit() True if all digits are numeric charactersis_bool() True if variable is a Booleanis_null() True if variable is NULLis_float() True if variable type is a fl o… Read More
  • How we know browser properties? echo $_SERVER['HTTP_USER_AGENT']; $browser = get_browser(); foreach ($browser as $name => $value) { echo “$name $value \n”; } get_browser   returns the capabilities of the user's browser. … Read More
  • Cookies Versus Sessions?  Cookies The setcookie( ) call needs to be before the HTML form because of the way the web works. HTTP operates by sending all "header" information before it sends "body" information. In the header, it sends t… Read More
  • What are the different tables present in mysql? Total 5 types of tables we can create 1. MyISAM 2. Heap 3. Merge 4. InnoDB 5. ISAM 6. BDB MyISAM is the default storage engine … Read More