Warning: INSERT command denied to user 'o4077762'@'infong892.perfora.net' for table 'watchdog' query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:14:\"strict warning\";s:8:\"%message\";s:102:\"Declaration of views_plugin_style_default::options() should be compatible with views_object::options()\";s:5:\"%file\";s:102:\"/homepages/27/d313962189/htdocs/poon.co/sites/all/modules/views/plugins/views_plugin_style_default.inc\";s:5:\"%line\";i:24;}', 3, '', 'http://poon.co/node/2182', '', '34.232.63.94', 1679319220) in /homepages/27/d313962189/htdocs/poon.co/includes/database.mysql.inc on line 135

Warning: INSERT command denied to user 'o4077762'@'infong892.perfora.net' for table 'watchdog' query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:14:\"strict warning\";s:8:\"%message\";s:151:\"Declaration of calendar_plugin_display_page::options_submit() should be compatible with views_plugin_display_page::options_submit(&$form, &$form_state)\";s:5:\"%file\";s:108:\"/homepages/27/d313962189/htdocs/poon.co/sites/all/modules/calendar/includes/calendar_plugin_display_page.inc\";s:5:\"%line\";i:297;}', 3, '', 'http://poon.co/node/2182', '', '34.232.63.94', 1679319220) in /homepages/27/d313962189/htdocs/poon.co/includes/database.mysql.inc on line 135

Warning: INSERT command denied to user 'o4077762'@'infong892.perfora.net' for table 'watchdog' query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:14:\"strict warning\";s:8:\"%message\";s:104:\"Declaration of calendar_plugin_display_page::options() should be compatible with views_object::options()\";s:5:\"%file\";s:108:\"/homepages/27/d313962189/htdocs/poon.co/sites/all/modules/calendar/includes/calendar_plugin_display_page.inc\";s:5:\"%line\";i:297;}', 3, '', 'http://poon.co/node/2182', '', '34.232.63.94', 1679319220) in /homepages/27/d313962189/htdocs/poon.co/includes/database.mysql.inc on line 135

Warning: INSERT command denied to user 'o4077762'@'infong892.perfora.net' for table 'watchdog' query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:14:\"strict warning\";s:8:\"%message\";s:105:\"Declaration of calendar_plugin_display_block::options() should be compatible with views_object::options()\";s:5:\"%file\";s:109:\"/homepages/27/d313962189/htdocs/poon.co/sites/all/modules/calendar/includes/calendar_plugin_display_block.inc\";s:5:\"%line\";i:78;}', 3, '', 'http://poon.co/node/2182', '', '34.232.63.94', 1679319220) in /homepages/27/d313962189/htdocs/poon.co/includes/database.mysql.inc on line 135

Warning: INSERT command denied to user 'o4077762'@'infong892.perfora.net' for table 'watchdog' query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:14:\"strict warning\";s:8:\"%message\";s:163:\"Declaration of calendar_plugin_display_attachment::options_submit() should be compatible with views_plugin_display_attachment::options_submit(&$form, &$form_state)\";s:5:\"%file\";s:114:\"/homepages/27/d313962189/htdocs/poon.co/sites/all/modules/calendar/includes/calendar_plugin_display_attachment.inc\";s:5:\"%line\";i:242;}', 3, '', 'http://poon.co/node/2182', '', '34.232.63.94', 1679319220) in /homepages/27/d313962189/htdocs/poon.co/includes/database.mysql.inc on line 135

Warning: INSERT command denied to user 'o4077762'@'infong892.perfora.net' for table 'watchdog' query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:14:\"strict warning\";s:8:\"%message\";s:110:\"Declaration of calendar_plugin_display_attachment::options() should be compatible with views_object::options()\";s:5:\"%file\";s:114:\"/homepages/27/d313962189/htdocs/poon.co/sites/all/modules/calendar/includes/calendar_plugin_display_attachment.inc\";s:5:\"%line\";i:242;}', 3, '', 'http://poon.co/node/2182', '', '34.232.63.94', 1679319220) in /homepages/27/d313962189/htdocs/poon.co/includes/database.mysql.inc on line 135

Warning: INSERT command denied to user 'o4077762'@'infong892.perfora.net' for table 'watchdog' query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:14:\"strict warning\";s:8:\"%message\";s:151:\"Declaration of calendar_plugin_display_ical::options_submit() should be compatible with views_plugin_display_page::options_submit(&$form, &$form_state)\";s:5:\"%file\";s:113:\"/homepages/27/d313962189/htdocs/poon.co/sites/all/modules/calendar/calendar_ical/calendar_plugin_display_ical.inc\";s:5:\"%line\";i:217;}', 3, '', 'http://poon.co/node/2182', '', '34.232.63.94', 1679319220) in /homepages/27/d313962189/htdocs/poon.co/includes/database.mysql.inc on line 135

Warning: INSERT command denied to user 'o4077762'@'infong892.perfora.net' for table 'watchdog' query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:14:\"strict warning\";s:8:\"%message\";s:134:\"Declaration of date_handler_field_multiple::pre_render() should be compatible with content_handler_field_multiple::pre_render($values)\";s:5:\"%file\";s:99:\"/homepages/27/d313962189/htdocs/poon.co/sites/all/modules/date/date/date_handler_field_multiple.inc\";s:5:\"%line\";i:185;}', 3, '', 'http://poon.co/node/2182', '', '34.232.63.94', 1679319220) in /homepages/27/d313962189/htdocs/poon.co/includes/database.mysql.inc on line 135

Warning: INSERT command denied to user 'o4077762'@'infong892.perfora.net' for table 'watchdog' query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:14:\"strict warning\";s:8:\"%message\";s:102:\"Declaration of calendar_view_plugin_style::options() should be compatible with views_object::options()\";s:5:\"%file\";s:106:\"/homepages/27/d313962189/htdocs/poon.co/sites/all/modules/calendar/includes/calendar_view_plugin_style.inc\";s:5:\"%line\";i:173;}', 3, '', 'http://poon.co/node/2182', '', '34.232.63.94', 1679319220) in /homepages/27/d313962189/htdocs/poon.co/includes/database.mysql.inc on line 135

Warning: INSERT command denied to user 'o4077762'@'infong892.perfora.net' for table 'watchdog' query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:14:\"strict warning\";s:8:\"%message\";s:136:\"Declaration of calendar_plugin_style_ical::init() should be compatible with views_plugin_style::init(&$view, &$display, $options = NULL)\";s:5:\"%file\";s:111:\"/homepages/27/d313962189/htdocs/poon.co/sites/all/modules/calendar/calendar_ical/calendar_plugin_style_ical.inc\";s:5:\"%line\";i:254;}', 3, '', 'http://poon.co/node/2182', '', '34.232.63.94', 1679319220) in /homepages/27/d313962189/htdocs/poon.co/includes/database.mysql.inc on line 135

Warning: INSERT command denied to user 'o4077762'@'infong892.perfora.net' for table 'watchdog' query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:14:\"strict warning\";s:8:\"%message\";s:102:\"Declaration of calendar_plugin_style_ical::options() should be compatible with views_object::options()\";s:5:\"%file\";s:111:\"/homepages/27/d313962189/htdocs/poon.co/sites/all/modules/calendar/calendar_ical/calendar_plugin_style_ical.inc\";s:5:\"%line\";i:254;}', 3, '', 'http://poon.co/node/2182', '', '34.232.63.94', 1679319220) in /homepages/27/d313962189/htdocs/poon.co/includes/database.mysql.inc on line 135
Exploring PDO | Lawrence Poon

Exploring PDO

Printer-friendly versionPDF version

Using mysql_connect() to connect to MySQL is easy, but it has many drawbacks. If your application uses another backend storage, you need to change the database function, for example, from mysql_connect pgsql_connect. A more important issue is it does not protect attacks from SQL Injection. These are the main reasons I started to explore PDO in my future PHP/MySQL projects.
I will rewrite my Generic Object with PDO later.
http://www.drupalschool.net/node/785

<?php
$database
= new Database();
$db = $database->getDB();

 
$sql = 'select * from Users';
   
$stmt = $db->query($sql);

      while (
$user = $stmt->fetch(PDO::FETCH_OBJ)){

          echo
$user->Lastname.' '.$user->Student_id.'<br />';

            }



// Connection data (server_address, database, username, password)

class Database {


private
$host = 'myHost';
private
$database = 'myDatabase';
private
$user = 'myUser';
private
$password = 'myPassword';
private
$db ;

public function
__construct() {

// Display message if successfully connect, otherwise retains and outputs the potential error
try {

$this->db = new PDO("mysql:host=$this->host; dbname=$this->database", $this->user, $this->password);


}

catch(
PDOException $e) {
  echo
$e->getMessage();
}


}
// constructor



public function getDB(){

return
$this->db ;
}


}
// class
?>