I'm trying to learn Yii, but I'm stuck with a very persistent error that rises whenever I use yiic.
First system details: Ubuntu 13.04 with apache2, php 5.5.3 and mysql 5.5.3.
I run/yiic migrate
inside /protected of the webapp I'm developing.
I get the error:
exception 'CDbException' with message 'CDbConnection failed to open the DB connection: could not find driver' in /var/www/yii/framework/db/CDbConnection.php:382
Which seems to be because at line 382 of CDbConnection.php, the script checks if pod_mysql is installed, but can't find it.
`if($this->_pdo===null)
{
if(empty($this->connectionString))
throw new CDbException('CDbConnection.connectionString cannot be empty.');
try
{
Yii::trace('Opening DB connection','system.db.CDbConnection');
$this->_pdo=$this->createPdoInstance();
$this->initConnection($this->_pdo);
$this->_active=true;
}
catch(PDOException $e)
{
if(YII_DEBUG)
{
throw new CDbException('CDbConnection failed to open the DB connection:'.
$e->getMessage(),(int)$e->getCode(),$e->errorInfo);
}
else
{
Yii::log($e->getMessage(),CLogger::LEVEL_ERROR,'exception.CDbException');
throw new CDbException('CDbConnection failed to open the DB connection.'
,(int)$e->getCode(),$e->errorInfo);
}
}
}
^^ Here is the relevant snippet of code.
The result of running
php -i|grep PDO gives
PDO
PDO support => enabled
PDO drivers => sqlite
PDO Driver for SQLite 3.x => enabled
So my problem seems to be that only the sqlite driver is running. However, I've ensured to check that php-mysql is installed (as pdo_mysql is deprecated and is inside this package). I've ran out of ideas on what to do, and will appreciate any and all help!!
Thanks in advance!
Console applications have their own config stored in protected/config/console.php. Please make sure you've got a database component configured there.
This problem is from your phpcli.ini instead of php.ini. in your phpcli.ini you should add :
extension=php_pdo_mysql.dll
as in php.ini
Related
I have this PHP function which has been working very well until i reinstalled my dev system:
function connectDB($database, $username, $password) {
$DSN = "mysql:host=localhost;dbname=$database";
try {
$DBH = new PDO($DSN, $username, $password); <--- LINE 10
return $DBH;
}
catch(PDOException $e) {
die("Could not connect to the database.\n");
}
}
And i'm getting the error:
PHP Fatal error: Class 'PDO' not found in /var/www/im/tools.php on line 10
I checked phpinfo() and PDO is enabled:
PDO drivers : mysql
PDO Driver for MySQL version: 5.1.54
The interesting thing is that the interaction with th MYSQL database is ok, but i'm still getting the error when debugging.
I'm puzzled about this error! My system is Ubuntu 11.04 + NGINX + PHP 5.3
Any tip to get rid of it? Thanks!
Are you using namespaced code? Maybe you need to use \PDO class then?
This can also happen if there is a php.ini file in the web app's current working directory. If one has been placed there to change certain settings, it will override the global one.
To avoid this problem, don't use a php.ini change settings; instead, do this in the vhost declaration or a .htaccess file with 'php_flag'.
See also PHP Fatal error: Class 'PDO' not found
try
yum install php-pdo
service httpd restart
I am getting this error when I'm trying to connect using PDO.
General error: 1651 Query cache is disabled; restart the server with query_cache_type=1 to enable it
I do not have access to MySQL terminal. I only have access to phpmyadmin via cPanel.
How can I fix this?
I tried this :-
try
{
$s = $conn->query("SET query_cache_type = 1");
}
catch(PDOException $e)
{
echo $e->getMessage();
}
But this didn't work.
How can I fix this?
This is a strange behavior of query_cache_type such that cannot be enabled if it wasn't enabled when the mysqld process started. But if it was enabled at startup, you can set query_cache_type "off" and then back on again if you need to.
That said, I would strongly encourage you to reconsider using the query cache at all. MySQL 8.0 has retired support for the query cache and removed it from the product. It's still a feature in MySQL 5.7, but it's deprecated as of 5.7.20.
On mac it worked after executing below command
sudo /your-path-to-mysql/mysql.server start --query-cache-type=1
sudo /usr/local/mysql/support-files/mysql.server start --query-cache-type=1
try this!
I have installed FreeTDS 0.91, ODBC, on a Cpanel server running Centos 6.5x64. Everything appears to be running fine and I can connect to the remote MSSQL 2012 server using:
/usr/local/freetds/bin/tsql -S sqlserver -U test -P mypassword
and succesfully execute queries in the database.
I can also connect through:
isql -v sqlserverdatasource test mypasswordhere
But for some reason /usr/local/freetds/bin/tsql -LH server.ip.here
returns no information or errors which doesn't make much sense when it is proven I can connect with the other methods above.
So now when running a test script from a cpanel account on the machine I get:
Unknown host machine name (severity 2)
Here is the test script:
//Database connection function.
function getConnection() {
try {
//$dbconnect = new PDO("sqlserver:Server=server.ip.here,1433;Database=dbname", "user", "password");
$dbconnect = new PDO("dblib:host=server.ip.here,1433;dbname=dbname", 'user', 'password');
} catch (PDOException $e) {
echo "CONNECTION ERROR.<br>Error message:<br><br>" . $e->getMessage();
die();
}
if (!$dbconnect) {
die('Cant connect to database. Please try again later!');
}
else{
echo "i'm in!";
return $dbconnect;
}
}
The first commented line is the old one using sqlserv which I found did not work at all from what i can tell because of the x64 OS. I have also tried with "" around user and pass as well as no marks at all.
php -m does show PDO and pdo-dblib.
Any ideas where I can look next?
Update: This was fixed. I missed in freetds.conf:
[global]
# TDS protocol version
tds version = 8.0
It was originally set to 4.5 instead of 8.
The fix for me was with three steps:
First, I edited /etc/freetds/freetds.conf and changed the tds version like this:
tds version = 8.0
The second step was not entering port number. The port was already 1433, and not specifying it fixed the exact same issue on my case.
Lastly, to connect properly, I had to restart networking as #user1054844 mentioned as this:
/etc/init.d/networking restart
After all these steps, I was able to connect and work with the SQL Server database.
You actually did not need ODBC at all since your connect script is using pdo_dblib not odbc. You can just install FreeTDS than enable pdo_dblib via the compile time flag in rawopts and rebuild via EasyApache. Of course cPanel specifics for this are a bit different.
I just did this for a friend and decided to document it since it is hard to find accurate clear information for FreeTds and pdo_dblib on cPanel.
Guide is here: FreeTDS And pDO_dblib On cPanel
I have this PHP function which has been working very well until i reinstalled my dev system:
function connectDB($database, $username, $password) {
$DSN = "mysql:host=localhost;dbname=$database";
try {
$DBH = new PDO($DSN, $username, $password); <--- LINE 10
return $DBH;
}
catch(PDOException $e) {
die("Could not connect to the database.\n");
}
}
And i'm getting the error:
PHP Fatal error: Class 'PDO' not found in /var/www/im/tools.php on line 10
I checked phpinfo() and PDO is enabled:
PDO drivers : mysql
PDO Driver for MySQL version: 5.1.54
The interesting thing is that the interaction with th MYSQL database is ok, but i'm still getting the error when debugging.
I'm puzzled about this error! My system is Ubuntu 11.04 + NGINX + PHP 5.3
Any tip to get rid of it? Thanks!
Are you using namespaced code? Maybe you need to use \PDO class then?
This can also happen if there is a php.ini file in the web app's current working directory. If one has been placed there to change certain settings, it will override the global one.
To avoid this problem, don't use a php.ini change settings; instead, do this in the vhost declaration or a .htaccess file with 'php_flag'.
See also PHP Fatal error: Class 'PDO' not found
try
yum install php-pdo
service httpd restart
I am trying to connect to my oracle database using PDO but I am getting Class PDO not found error. I have checked that PDO is enabled and it appears so. Still I am not able to trace why I am getting this error. Here is my configure command,
cscript /nologo configure.js "--enable-snapshot-build" "--enable-debug-pack"
"--with-snapshot-template=d:\php-sdk\snap_5_2\vc6\x86\template"
"--with-php-build=d:\php-sdk\snap_5_2\vc6\x86\php_build"
"--with-pdo-oci=D:\php-sdk\oracle\instantclient10\sdk,shared"
"--with-oci8=D:\php-sdk\oracle\instantclient10\sdk,shared"
PHP ver : 5.2.8
Oracle: 10.2
This is the code I am using to connect to the db.
try{
$conn = new PDO("oci:dbname=".$oc_db,$oc_user,$oc_pass);
}catch(PDOException $e){
echo ($e->getMessage());
}
Can there be any other reason that I am getting this error? Any help appreciated.
This generally means the PDO extension in question isn't compiled and set up so PHP can use it. What operating system are you compiling PHP on?
I'm not sure if PDO core module is compiled if you only specify to compile the oracle extension of it (PDO-OCI).
You should check out the PHP manual regarding how to install and enable the PDO module.
You should look at these sites:
http://is.php.net/manual/en/pdo.installation.php
http://is.php.net/manual/en/ref.pdo-oci.php
Check my question I troubleshoot this and other errors but then Im stuck,
No records found ...Agiletoolkit and Oracle. Grid/CRUD elements
My Oracle connection string in agiletoolkit config-default.php file looks like this:
$config['dsn']= array( 'oci:dbname=localhost/MYDATABASE', 'MYUSER', 'MYPASSWORD' );
To fix the driver not found error, I enabled extension=php_pdo_oci8.dll in the php.ini file from my apache installation.
Then there was an error about a missing "oci.php", to solve that I had to create my own file like this:
class DB_dsql_oci extends DB_dsql {
function limit($cnt,$shift=0){
$cnt+=$shift;
$this->where('NUM_ROWS>=',$shift);
$this->where('NUM_ROWS<',$cnt);
return $this;
}
function render_limit(){
return '';
}
}
and placed it at: ...atk4\lib\DB\dsql
To fix the special chars error from oracle , I set line 59 on /atk4/lib/DB/dsql.php to empty string like this: public $bt='';
I manage to run the database test, and it says "Successfully connected to database."