Cake php Datasource class MySQL could not be found - php

I have ubuntu 10.04 on server.
I am trying to set up the cake php project but it gives me following error
Cake is NOT able to connect to the database.
Datasource class MySQL could not be found.
I have searched lot on the web regarding it.
my config file looks like this
class DATABASE_CONFIG {
public $default = array(
'datasource' => 'Database/MySQL',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => 'mypassword',
'database' => 'dbname',
'prefix' => '',
//'encoding' => 'utf8',
);
}
I checked that server has all the things set up to connect as PDO I have run following script and it works fine.
$conn = new PDO('mysql:host=localhost;dbname=dbname', $username, $password);
Then further I have changed in Mysql.php file of cake php which is in the "lib\Cake\Model\Datasource\Database"
I tried to give static connection in Mysql.php but this also doesn't work. I did exit in the Mysql.php and seems like control of page is not getting here.
$this->_connection = new PDO('mysql:host=localhost;dbname=dbname', $username, $password);
$this->connected = true;
Please do let me know if I am missing anything.
Thanks in Advance.

Casing matters, it should be:
'datasource' => 'Database/Mysql'
And not:
'datasource' => 'Database/MySQL'

Mysql is not a supported source try 'datasource' => 'Database/Sqlite',

Related

sqlsrv_connect works fine in php but fails in laravel on the same server(AWS EC2 Instance)

I am trying to connect MSSQL database as my second database in Laravel, In the core PHP file It works fine but when I try to connect in the laravel It throws an error.
Here is my .env
MSSQL_CONNECTION=sqlsrv
MSSQL_DATABASE_URL='/EC2AMAZ-61LPEGK\SQLEXPRESS'
MSSQL_HOST=XX.XX.X.XXX
MSSQL_PORT=1433
MSSQL_DATABASE="/dbcrm"
MSSQL_USERNAME="sauser"
MSSQL_PASSWORD='dbpassword123'
MSSQL_TRUSTSERVER='yes'
MSSQL_ENCRYPT=False
MSSQL_STRICT=false
and here is my laravel database config:
'sqlsrv' => [
'driver' => 'sqlsrv',
'url' => env('MSSQL_DATABASE', '/EC2AMAZ-61LPEGK\SQLEXPRESS'),
'host' => env('MSSQL_HOST', 'XX.XX.X.XXX'),
'port' => env('MSSQL_HOSTDB_PORT', '1433'), //I had tried null
'database' => env('MSSQL_DATABASE', '/dbcrm'), //tried without '/'
'username' => env('MSSQL_USERNAME', 'sauser'),
'password' => env('MSSQL_PASSWORD', 'dbpassword123'),
'trust_server_certificate' => env('MSSQL_TRUSTSERVER', 'yes'), //tried 'no'
'encrypt' => env('MSSQL_ENCRYPT', False), //tried true
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
],
Here is the PHP file code which works fine and connect the database as well as execute the query,
$host ="XX.XX.X.XXX";
$username ="sauser";
$password ="dbpassword123";
$database ="dbcrm";
$params = [
"UID" => $username,
"PWD" => $password,
"Database" => $database,
"TrustServerCertificate" => "yes",
];
if(sqlsrv_connect($host, $params)) {
echo "connected..";
} else {
echo "Connection could not be established.<br />";
echo "<pre>";
die( print_r( sqlsrv_errors(), true));
echo "</pre>";
}
I am using the same server for both cases and I have installed/enabled SQLSRV. Please find the phpinfo screenshots for reference.
Why it is working in PHP file but not in the Laravel. Please help.
Note : MSSQL database is installed on another AWS windows Instance and TCP is enabled, and port number is 1433
Here is the error what I am getting,
Finally, able to figure out the issue, Posting the same so it will help someone who has struck for days and ripping their hair out to find the solution.
Change the below .env variables and database config as below,
MSSQL_ENCRYPT=yes
MSSQL_TRUSTSERVER=True
config/database.php
'trust_server_certificate' => env('MSSQL_TRUSTSERVER', true), //Some libraries accessing ODBC/JBDC require Yes/No settings, others True/False,
'encrypt' => env('MSSQL_ENCRYPT', 'yes'), //same here try Yes/No or True/False

Doctrine php DBAL not working

New to doctrine php and I followed each instruction to the point. Downloaded doctrine using composer as instructed on http://www.doctrine-project.org/projects/dbal.html and then on my index.php I added this http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#getting-a-connection only changing the test database credentials.
include_once 'vendor/autoload.php';
$config = new \Doctrine\DBAL\Configuration();
$connectionParams = array(
'dbname' => 'teastdb',
'user' => 'root',
'password' => '',
'host' => 'localhost',
'driver' => 'pdo_mysql',
);
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
and this does not work (shows blank page, I even inserted both right and wrong credential for testing purpose). What is wrong?
Here is a screenshot as well

ZF2 Zend\Paginator\Adapter\DbSelect on DB2 i Series

Im creating a Zend APIgility application REST service and having a problem with my fetchAll Mapper function.
I'm connecting to an IBM DB2 database running on an i Series server (AS/400) via DB2 Connect on a Windows Application Server.
My Connection is is made in my local.php as such:
return array(
'db' => array(
'driver' => 'IbmDb2',
'database' => $database,
'username' => $user,
'password' => $password,
'hostname' => $host,
'port' => $port,
'driver_options' => array(
'i5_naming' => DB2_I5_NAMING_ON,
'i5_lib' => 'LIBWEB',
),
),
);
The fetchAll() function in my Mapper class is:
public function fetchAll()
{
$select = new Select('WBRESOURCE');
$paginatorAdapter = new DbSelect($select, $this->adapter);
$collection = new ResourcesCollection($paginatorAdapter);
return $collection;
}
When I hit the DbSelect, ZF2 throws the following DB2 Connect error:
"[IBM][CLI Driver][AS] SQL0204N \"*LIBL.WBRESOURCE\" is an undefined name. SQLSTATE=42704"
Im not sure why its using *LIBL (user defined library list), since I defined the library (SCHEMA) to use as LIBWEB in my connection option.
Thanks in advance!
Rob
Try changing this section:
'driver_options' => array(
'i5_naming' => DB2_I5_NAMING_ON,
'i5_lib' => 'LIBWEB',
Change to":
'driver_options' => array(
'i5_naming' => DB2_I5_NAMING_OFF, <=== change
'i5_lib' => 'LIBWEB',
By using DB2_I5_NAMING_OFF, you should get SQL naming mode. The use of DB2 i5 naming mode will result in things like reliance on a job's library list.
See PHP: db2-connect for some info on the parameter.

CakePHP - Setup database with a form

I would like to setup the database in CakePHP providing host, login and password with a form (so without writing the database.php file myself). The purpose is some kind of automatic setup of CakePHP (I would use this to provide salt and cypherSeed too).
Is this possible? What's the best way to do go? I read something about writing file via PHP...
If you create/load your database connection from your controller you can have this data variable. I don't think it's a good idea to write database.php file with a form.
So I would do something like this:
//Controller
$this->Formdatabase = ClassRegistry::init('Formdatabase');
$db_host = '';//load from file or DB
$db_user = '';//load from file or DB
$db_pass = '';//load from file or DB
$db_database = '';//load from file or DB
ConnectionManager::create("form_database", array(
'datasource' => 'Database/Mysql',
'driver' => 'mysql',
'persistent' => false,
'host' => $db_host,
'login' => $db_user,
'password' => $db_pass,
'database' => $db_database,
'prefix' => '',
'encoding' => 'UTF8',
'port' => '',
));
$this->Formdatabase->useTable = ''; //table you want to use. (in Model or controller)
//Model
<?php
class Formdatabase extends Model {
public $useDbConfig = 'form_database';
}
?>
//Now you can use $this->Formdatabase->find('...'); ...
Hope I could help, good luck!

Making CakePHP work with SQL server 2008

I can call SQL server 2008 from PHP with Microsoft Drivers for PHP for SQL Server But as Sqlsvr driver class is needed to use CakePHP with SQL server 2008, I got the driver file from following repository.
However, when running my test cakephp with following database.php
<?php
class DATABASE_CONFIG {
var $default = array(
'driver' => 'sqlsvr',
'host' => 'localhost\EPHP',
'login' => 'sa',
'password' => 'xxxxxxx',
'database' => 'Blog',
);
}
?>
I got following error:
Fatal Error (256): ConnectionManager::loadDataSource - Unable to import DataSource class .DboSqlsvr [CORE\cake\libs\model\connection_manager.php, line 185]
Then I have read all the you-cannot-make-cakePHP-work-with-sql-2008 discussions. Is there any resolution by now?
UPDATE: Let me rephrase my question. I would appreciate if someone successfully made CakePHP work with SQL 2008 and tell me the procedure he followed to do that.
After some research, I found this article ( http://book.cakephp.org/view/1652/Plugin-DataSources-and-Datasource-Drivers). Basically, you can not place your driver file in the directory ( \cakephp\cake\libs\model\datasources\dbo) where the "factory" driver files are located. Instead you should place the driver file in following directory of your baked cake.
your-cake-application\plugins\your-plugin-name\models\datasources\dbo
And then you should change your database.php in config accordingly.
<?php
class DATABASE_CONFIG {
var $default = array(
'driver' => 'your-plugin-name.DboSqlsrv',
'host' => 'localhost\EPHP',
'login' => 'sa',
'password' => 'xxxxxxx',
'database' => 'Blog',
);
}
?>
After this, I could run my cakephp app.
Assuming you have the datasources in the folder app/model/datasource/dbo_sqlsrv.php load it like this:
<?php
class DATABASE_CONFIG {
var $default = array(
'datasource' => 'sqlsvr',
'host' => 'localhost\EPHP',
'login' => 'sa',
'password' => 'xxxxxxx',
'database' => 'Blog',
);
}
?>
The difference is in the 'driver' vs 'datasource' keyword

Categories