Situation:
I am creating a database user interface for a client's website. I know I could simply use phpMyAdmin, but it is too complex for my client. Instead, I though I could give some of the PEAR Packages a try. After doing some research and following tutorials I decided to go with the Structures_DataGrid package. I am currently following sitepoint.com's book, 'The PHP Anthology'. It contains some great tutorials.
Error:
First of all, I had some difficulty installing the packages so I ended up downloading them from the PEAR website and inserting them int he server via FTP. After all that was setup, I followed the book's instructions to the last semicolon. But i get this error: Unknown DataSource driver. Please specify an existing driver. I have no idea where this error is coming from or why.
Code:
<?php
// Include PEAR::Structures_DataGrid
include('Structures/DataGrid.php');
$datagrid = new Structures_DataGrid(2);
$options = array('dsn' => 'mysql://$user:$passwords@$db_host/$db_name');
$sql = "SELECT * FROM Users";
$bind = $datagrid->bind($sql, $options);
if (PEAR::isError($bind)) {
print('DataGrid Error: '. $bind->getMessage());
$gridsource = '';
} else {
// Define our Column labels, using a 'column' => 'Label' format
$columns = array(
'id' => 'Id',
'status' => 'Status',
'last_login' => 'Last Login',
'startDate' => 'Start Date',
'fname' => 'First Name',
'lname' => 'Last Name',
'email' => 'Email',
'cName' => 'Company',
'cEmail' => 'Company Email',
'cCity' => 'City',
'cProvince' => 'Province',
'ctr' => 'Country',
'cSite' => 'Website'
);
$datagrid->generateColumns($columns);
// Some more options, for our renderer
$renderer_options = array(
'sortIconASC' => '⇑',
'sortIconDESC' => '⇓',
'headerAttributes' => array('bgcolor' => '#E3E3E3'),
'evenRowAttributes' => array('bgcolor' => '#A6A6A6'),
);
$datagrid->setRendererOptions($renderer_options);
// Add some final attributes to our table
$renderer = $datagrid->getRenderer();
$renderer->setTableAttribute('cellspacing', 0);
$renderer->setTableAttribute('cellpadding', 5);
$renderer->setTableAttribute('border', 1);
// Render the table, be sure to check for errors
$gridbody = $datagrid->getOutput();
if (PEAR::isError($gridbody)) {
print('DataGrid render error: ' . $gridbody->getMessage());
$gridbody = '';
}
// Finally, render the pager, again checking for errors
$gridpager = $datagrid->getOutput(DATAGRID_RENDER_PAGER);
if (PEAR::isError($gridpager)) {
print('DataGrid render error: ' . $gridpager->getMessage());
$gridpager = '';
}
$gridsource = $gridbody . $gridpager;
}
?>
Comments:
All of my database credentials are correct. I am trying to connect to a MySQL database on a Unix server. I am sure I have all the required packages. I do not think that the error is here in the code. Rather it is an issue with the driver not being enabled or something like that.
Question:
Well, I am not sure what my question is because I am not sure what my problem is. I could ask things like 'How do I specify a driver?', 'How do I enable/activate/include a driver?' or 'Has anybody had to dealt with these issues before, and what did you do?'
Any help would be greatly appreciated, thanks in advance.