Crate/PDO Usage Examples

376 views Asked by At

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.

2

There are 2 answers

4
Sebastian Utz On BEST ANSWER

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;
} 
3
Sectona On

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;

}


?>