Trouble getting my dhtmlx php script to connect to MySql

872 Views Asked by At

I have the following PHP (thirdExampleConnector.php):

<?php
  require_once("/path/to/dhtmlx/dhtmlxConnector/codebase/grid_connector.php");
  require_once("/path/to/dhtmlx/dhtmlxConnector/codebase/db_pdo.php");

  $dbh = new PDO("mysql:host=127.0.0.1;port=3666;dbname=testdb", "root", "rootpw", array( PDO::ATTR_PERSISTENT => false));

  $conn = new GridConnector($dbh,"PDO");
  $conn->render_table("Writers","Id","Name");
?>

And it seems to work reasonably from the command line:

> php /path/to/verification/plans/app/thirdExampleConnector.php

<?xml version='1.0' encoding='utf-8' ?>
<rows><row id='1'><cell><![CDATA[Jack London]]></cell></row>
<row id='2'><cell><![CDATA[Honore de Balzac]]></cell></row>
<row id='3'><cell><![CDATA[Lion Feuchtwanger]]></cell></row>
<row id='4'><cell><![CDATA[Guy de Maupasant]]></cell></row>
<row id='5'><cell><![CDATA[Truman Capote]]></cell></row>
</rows>

But when I access it through the browser I get the error message:

 <br />
 <b>Fatal error</b>:  Uncaught exception 'PDOException' with message 'could not find driver' in /path/to/verification/plans/app/thirdExampleConnector.php:10
 Stack trace:
 #0 /path/to/verification/plans/app/thirdExampleConnector.php(10): PDO-&gt;__construct('mysql:host=loca...', 'root', 'rootpw')
 #1 {main}
 thrown in <b>/path/to/verification/plans/app/thirdExampleConnector.php</b> on line <b>10</b><br />

Here is the html file (if it makes any difference):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<html>
  <head>
    <link rel="STYLESHEET" type="text/css" href="../../../dhtmlx/dhtmlxGrid/codebase/dhtmlxgrid.css">
    <script src="../../../dhtmlx/dhtmlxGrid/codebase/dhtmlxcommon.js"></script>
    <script src="../../../dhtmlx/dhtmlxGrid/codebase/dhtmlxgrid.js"></script>
    <script src="../../../dhtmlx/dhtmlxGrid/codebase/dhtmlxgridcell.js"></script>
    <script src="../../../dhtmlx/dhtmlxDataProcessor/codebase/dhtmlxdataprocessor.js"></script>
    <script src="../../../dhtmlx/dhtmlxForm/codebase/dhtmlxform.js"></script>
    <script src="../../../dhtmlx/dhtmlxForm/samples/06_data/php/connector/connector.js"></script>
    <div id="box" style="width:350px; height:160px; background-color:white;"></div>
    <div id="box2" style="width:350px; height:100px; background-color:white;"></div>
  </head>
  <body>
    <script type="text/javascript">
      window.onload = function(){

        //---grid initialization
        var myGrid = new dhtmlXGridObject('box');          // object constructor
        myGrid.setHeader("Name");                          //specifies the grid's headers
        myGrid.setSkin("xp");                              //initializes the grid
        myGrid.init();                                     //initializes the grid
        myGrid.load("thirdExampleConnector.php");          //populates the grid with data from the DB

      }
    </script>
  </body>
</html>

One difference that I know of is that the web version of php is 5.2.5 and the command line version is 5.3.3 but I do not think I have any control over the which version of PHP the web server is using.

Is there a workaround for this?

0

There are 0 best solutions below