FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


MySql: Could not find driver





rvbarreto
I made a sql databank and I try to acess it using PDO and I can't make it work because I receive this message:

"could not find driver
Fatal error: Call to a member function query() on a non-object"

Does frihost suport PDO?
If yes, what happened?
kv
frihost supports pdo, both in server1 and server2.

http://www.frih.net/phpinfo.php
http://www.frihost.com/phpinfo.php

The error you are getting may be due to some configuration. Posting a portion of your code might help.
rvbarreto
I am using this to get connected to database:

Code:
<?php
$dns="mysql:host=localhost;dbname=rvbarret_ergosum";
$user="rvbarret_admin";
$pass="";
try{
   $con = new PDO($dns, $user, $pass);
}catch (PDOException $e){
   echo $e->getMessage();
}
   
?>


Then to use the data base I made this:

Code:
<?php
//open connection
require_once("../../acoes/conectar.php");

//sql command
   $canal = "cerveja";
   $sql = "SELECT titulo,data FROM posts WHERE area='$canal'";
   
//execute sql command
   $stmt=$con->query($sql);
   
//convert to array
   if(!is_object($stmt)){
        throw new Exception("Erro no comando sql!");
   }
   $dados = $stmt->fetchAll();
   
//close connection
   unset($con);
   
//check data
   if(empty($dados)){
      throw new Exception("Nao encontrado");
   }

//use obtained data
   foreach ($dados as $d){
      include("../post/".$d['data']."-".$d['titulo'].".php");
   }
   ?>


The debug sad that the error is in the "$stmt=$con->query($sql);" line.
What I can't undestand is that when I simulate it in my computer, it works fine.

To see the error page:

http://ergosum.frihost.net/canais/cerveja/
kv
rvbarreto wrote:


I am using this to get connected to database:

<?php
$dns="mysql:host=localhost;dbname=rvbarret_ergosum";
$user="rvbarret_admin";
$pass="";
$con=null; //<--declare variable here
try{
$con = new PDO($dns, $user, $pass); // <-- $con is local here
}catch (PDOException $e){
echo $e->getMessage();
}

?>

Then to use the data base I made this:

<?php
//open connection
require_once("../../acoes/conectar.php");

//sql command
$canal = "cerveja";
$sql = "SELECT titulo,data FROM posts WHERE area='$canal'";

//execute sql command
$stmt=$con->query($sql);


If you observe conectar.php, $con is a local variable inside the try block. Therefore, it is not accessible in your $stmt=$con->query($sql); line.

What you can do is to declare this variable outside the try block.



Code:

<?php
$dns="mysql:host=localhost;dbname=rvbarret_ergosum";
$user="rvbarret_admin";
$pass="";
try{
   $con = new PDO($dns, $user, $pass); // <-- $con is local here
}catch (PDOException $e){
   echo $e->getMessage();
}
   
?>
rvbarreto
I was studing here in my wamp server, I enable mysql PDO driver. But here in frihost, they just enable sqlite and sqlite2 pdo driver's. That is why it doesn't work.

If instead of write

Quote:


$dns="mysql:host=localhost;dbname=rvbarret_ergosum";
$user="rvbarret_admin";
$pass="";



I write this:

Quote:

$dns="sqlite:host=localhost;dbname=rvbarret_ergosum";
$user="rvbarret_admin";
$pass="";
?>


It gives a diferent error message, associate to other problems.

Now, i would like to use mysql instead of sqlite... is there a way? does any one can enable mysql pdo driver?
Related topics
E-Cards with PHP & MySQL
where can i find mySQL ?
Where can I find tutorials for MySQL?
Servlets
Dell or Lenovo?
mysql syntax error I can't find why
Linux & Dell C-610 Laptop. Please find me a fan driver.
Can't find driver
mysql java connector classpath error
php-mysql source code
Jsp Error Cant Get Data from database
find me BCM92035DGROM driver
Mysql and PDO
Getting error on ODBC driver
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.