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.

4

2 回答 2

3

Crate PDO 适配器不是 PHP PDO 官方支持和包含的,所以必须使用 Crate PDO 类而不是标准 PDO 类。

您应该通过以下方式导入 Crate\PDO\PDO 类use Crate\PDO\PDO;

或使用完全限定的类名:

<?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;
} 
于 2014-11-27T22:46:16.060 回答
-4

只要这样做,你就会没事的。如果您需要更多帮助,请告诉我.... 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;

}


?>
于 2014-11-27T20:52:02.983 回答