1

Has anyone successfully installed Crate/PDO.

I seem to be banging my head against this one.

I have used composer to create the json file and when i try to

<?php

require 'vendor/autoload.php';

try {
  $dbh = new PDO('crate:localhost:4200');
  foreach($dbh->query('SELECT * from testtable') as $row) {
      print_r($row);
  }
  $dbh = null;
} 

catch (PDOException $e) {
  print "Error!: " . $e->getMessage() . "<br/>";
  die();
}

?>

It comes up with error Could not find driver.

Any help or installation documents would be great. anyone got any example code working.

ScottJShea
  • 7,041
  • 11
  • 44
  • 67
Graham
  • 13
  • 2

2 Answers2

3

The Crate PDO adapter is not official supported and included by PHP PDO, so the Crate PDO class must be used instead of the standard PDO class.

You should either import the Crate\PDO\PDO class by use Crate\PDO\PDO;

or use a full qualified classname:

<?php

require 'vendor/autoload.php';

try {
  $dbh = new \Crate\PDO\PDO('crate:localhost:4200', null, null, []);
  foreach($dbh->query('SELECT * from testtable') as $row) {
      print_r($row);
  }
  $dbh = null;
} 
Sebastian Utz
  • 719
  • 3
  • 9
  • unforunately i am getting Fatal error: Class 'Crate\PDO\PDO' not found in /var/www/html/index.php on line – Graham Nov 28 '14 at 08:41
  • No worries. you led me down the right path. Composer wasnt working correctly. Now its pulling in the correct dependancies it is working. Nice Work. – Graham Nov 28 '14 at 09:05
  • @Graham, could you share what you did to fix the Class not found problem? I'm running into the same thing. I don't have much experience with composer yet, but it looks like it downloaded lots of stuff to the vendor dir, although I don't see any files or dirs called crate... – Michael Jan 07 '15 at 15:15
  • @michael, i was pulling my vendor files into a different folder that u was referencing in my php file. Once I had got the auto load file in the right place it all started working – Graham Jan 08 '15 at 22:52
-4

Just do it this way and you will be okay. Give me a shout if you needs more help.... Sectona

pdo_connect.php

<?php




$db = new PDO (
    'mysql:host=localhost;dbname=sectona_db;charset=utf8', 
    'root', // username

    'root6a' // password
);

?>






<?php


require("pdo_connect.php");






$result = $db->prepare('SELECT table_data,table_name FROM testable');

        $result->execute(array(
            '
    ));




    while ($row = $result->fetch()) {



$tb1=htmlentities($row['table_data'], ENT_QUOTES, "UTF-8");
$tb2=$pid=htmlentities($row['table_name'], ENT_QUOTES, "UTF-8");

echo $tb1;
echo $tb2;

}


?>
Sectona
  • 98
  • 1
  • 9