I am writing below query after connecting sql server in cakephp 2.x.
$this->User->find('first', array('conditions' => array('User.USER_ID' => 1)));
This produces following query
SELECT TOP 1 [User].[USER_ID] AS [User__USER_ID], [User].[USER_NAME] AS [User__USER_NAME]
FROM [ec_user_details] AS [User]
WHERE [User].[USER_ID] = 1
The above query through following error
SQLSTATE[42S02]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid object name 'ec_user_details'.
How can I create the following query by ORM in cakephp
SELECT TOP 1 [User].[USER_ID] AS [User__USER_ID], [User].[USER_NAME] AS [User__USER_NAME]
FROM [**DB_NAME**].[ec_user_details] AS [User]
WHERE [User].[USER_ID] = 1
Please help
After spending lots of time I found the solutions. Add schema in the db config
public $default = array(
'host' => '127.0.0.1',
'login' => 'username',
'password' => 'paasword',
'database' => 'db_name',
'datasource' => 'Database/Sqlserver',
'persistent' => false,
'prefix' => '',
'encoding' => PDO::SQLSRV_ENCODING_UTF8,
'schema'=>'db_name'
);
Related
That is my local.php config:
'db' => array(
'driver' => 'pdo_mysql',
'dns' => 'mysql:dbname=xxxx;host=localhost;',
'username' => 'xxxx',
'password' => 'xxxx',
'port' => 3306,
'charset' => 'UTF8',
'driver_options' => array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
),
),
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
)
)
And that is my authentication code:
$authAdapter = new AuthAdapter($sm->get('Zend\Db\Adapter\Adapter'));
$authAdapter->setTableName('users')
->setIdentityColumn('username')
->setCredentialColumn('password')
->setCredentialTreatment("SHA2(CONCAT({$salt}, ?, salt), '512') AND active = 1");
$authAdapter->setIdentity($formData['username'])
->setCredential($formData['username']);
But when I try to submit login form, zend framework throw this errors:
File: /var/www/app/vendor/zendframework/zend-authentication/src/Adapter/DbTable/AbstractAdapter.php:331
Message: The supplied parameters to DbTable failed to produce a valid sql statement, please check table and column names for validity.
File: /var/www/html/bookingSystemRewrite/vendor/zendframework/zend-db/src/Adapter/Driver/Pdo/Statement.php:244
Message:Statement could not be executed (3D000 - 1046 - No database selected)
File:/var/www/html/bookingSystemRewrite/vendor/zendframework/zend-db/src/Adapter/Driver/Pdo/Statement.php:239
Message:SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected
When I debug Pdo Driver Adapter I found where is my problem.
The first problem was in that order:
'dns' => 'mysql:dbname=xxxx;host=localhost;'
it must be so :
'dsn' => 'mysql:dbname=xxxx;host=localhost;'
And the second problem was in that order:
->setCredentialTreatment("SHA2(CONCAT({$salt}, ?, salt), '512') AND active = 1");
it must be so:
->setCredentialTreatment("SHA2(CONCAT('{$salt}', ?, salt), '512') AND active = 1");
I am unable to get response from this code
if (!empty($data)) {
$json_response = json_encode($data);
echo $json_response;exit;
} else {
echo '';
}
here data is a coming from database in $data but not able to encode it.
$data containing following data
Array
(
[0] => Array
(
[doctor_id] => 1
[d_name] => Rahul Kenewadekar
[country] => India
[year] => DNB - 2012 to 2014
[profile_image] => Rahul_Kenewadekar-1439468566.jpg
[department] => Fellowship in MAS � DNB (Minimal Access Surgery -
Diplomate of National Board)
)
What is your database and table's encoding type(charset). Also you can check in app/config/database.php if the setting is set as below:
<?php
class DATABASE_CONFIG
{
var $default = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'XXXXXX',
'password' => 'XXXXXXXX',
'database' => 'XXXXXXXX',
'prefix' => '',
'encoding' => 'utf8'
);
You can also try doing "SET NAMES UTF8" before executing any query and just after doing connection to your DB.
I am taking the Zend Framework 2 Skeleton tutorial but have elected to use the mysql database in my container at my.phpcloud.com.
In the global.php file I have:
return array(
'db' => array(
'driver' => 'Pdo',
'dsn' => 'mysql:dbname=mycontainer;host=mycontainer-db.my.phpcloud.com',
'driver_options' => array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
),
),
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter'
=> 'Zend\Db\Adapter\AdapterServiceFactory',
),
),
);
In my local.php file I have:
return array(
'db' => array(
'username' => 'mycontainer',
'password' => 'mypassword',
),
);
I receive no errors, even if I purposely put in incorrect credentials. My view loads properly...except that there are no records. I've verified that the table exists and it is named correctly. I've verified that the table contains records.
If I return the Controller to call an array for the view, rather than a populated ViewModel, it loads the view with errors, as expected, since the AlbumTable does not load. In other words, the View is being routed correctly. It just seems like the database is returning no results. I've copied and pasted everything to the correct files and triple checked it all. I completed this tutorial locally with Zend Server and MySql and it runs perfectly. It's just the PHPCloud, which issues no errors, that seems to be returning no records from its database, whether I purposely introduce bad credentials or not.
Thanks for any assistance in advance.
Try something like this:
$dsn = sprintf(
'mysql:dbname=%s;host=%s',
get_cfg_var('zend_developer_cloud.db.name'),
get_cfg_var('zend_developer_cloud.db.host')
);
return array(
'db' => array(
'driver' => 'pdo',
'dsn' => $dsn,
'username' => 'mycontainer',
'password' => 'mypassword',
),
);
I am trying to setup apache solr search for one of my project. I have installed solr 3.6 in my development server and it is reachable with
http://127.0.0.1:8080/solr/admin/
I tried to put the sample application available in php manual but it is setting username and password for solr. I am not sure where can I get this information from. I have also tried below code from net but I was getting 500 error whenever I run it
$options = array (
'hostname' => '127.0.0.1',
);
//$client = new SolrClient($options, "4.0"); // use 4.0 for any version of Solr 4.x, ignore this parameter for previous versions
$doc = new SolrInputDocument();
$doc->addField('id', 100);
$doc->addField('title', 'Hello Wolrd');
$doc->addField('description', 'Example Document');
$doc->addField('cat', 'Foo');
$doc->addField('cat', 'Bar');
$response = $client->addDocument($doc);
$client->commit();
/* ------------------------------- */
$query = new SolrQuery();
$query->setQuery('hello');
$query->addField('id')
->addField('title')
->addField('description')
->addField('cat');
$queryResponse = $client->query($query);
$response = $queryResponse->getResponse();
print_r( $response->response->docs );
Please help
your solr version is 3.6 so you should assign $client = new SolrClient($options);
$client = new SolrClient($options, "4.0"); // I see that in your code you commented this line which is required thinking that it is only for solt 4.x in your case, you should uncomment it and only remove the "4.0" in order to create a client.
To create a client :
$options = array (
'host' => "localhost",
'port' => 8983, //port is required
'path' => '/solr/collection1', //collection1 or core are mandatory it can be just /solr/
);
$client = new SolrClient($options); //for solr 3.x
According to the example code, you are not setting the port in your $options array. Should be:
var $options = array(
'hostname' => '127.0.0.1',
'port' => '8080',
);
That could be the cause of the 500 error.
you need to add 3 things host, port, and webapp. I hope you have included the service.php file in that.
var $options = array(
'hostname' => '127.0.0.1',
'port' => '8080', //Port number where solr runs.
'webapp' => '/solr/', //path of the webapp.
);
Master site configuration
For settings.php file in your master site you do not have to change much. Leave your $databases array as it as. Master site will store all the user names, passwords, and sessions.
For settings.php file in your master site you do not have to change much. Leave your $databases array as it as. Master site will store all the user names, passwords, and sessions.
$databases = array(
'default' =>
array(
'default' =>
array(
'database' => 'drupal1',
'username' => 'username',
'password' => 'password',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
),
),
);
Slave sites configuration
The slave sites shall be connected to the Master site's database for certain tables, specially the ones that include user information. For settings.php file in your slave sites you need to specify master site database and call its users and other tables. We can do so by adding configuration settings within the "prefix" key of the $databases array.
$databases = array(
'default' =>
array(
'default' =>
array(
'database' => 'drupal2',
'username' => 'username',
'password' => 'password',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => array(
'default' => 'drupal2.',
'users' => 'drupal1.',
'sessions' => 'drupal1.',
'role' => 'drupal1.',
'authmap' => 'drupal1.',
'users_roles' => 'drupal1.',
),
),
),
);
For more detailed instruction visit - How to set up and use Apache Solr in php
Fatal error: Uncaught exception 'Zend_Db_Table_Exception' with message
'No adapter found for Zend_Session_SaveHandler_DbTable' in
C:\wamp\www\hol\library\Zend\Db\Table\Abstract.php on line 755 ( ! )
Zend_Db_Table_Exception: No adapter found for
Zend_Session_SaveHandler_DbTable in
C:\wamp\www\hol\library\Zend\Db\Table\Abstract.php on line 755 Call
Stack
Time Memory Function Location 1 0.0005 373664 {main}( ) ..\init.php:0
2 0.0325 2749720 Zend_Session_SaveHandler_DbTable->__construct(
) ..\init.php:40 3 0.0325 2750168 Zend_Db_Table_Abstract->__construct(
) ..\DbTable.php:207
4 0.0325 2750480 Zend_Session_SaveHandler_DbTable->_setup(
) ..\Abstract.php:268 5 0.0325 2750480 Zend_Db_Table_Abstract->_setup(
) ..\DbTable.php:403
6 0.0325 2750480 Zend_Db_Table_Abstract->_setupDatabaseAdapter(
) ..\Abstract.php:739
Code:
//Configuration consumption
$config = new Zend_Config(require 'config.php');
//Database configuration
$db = Zend_Db::factory($config->database->adapter, array(
'host' => $config->database->params->host,
'username' => $config->database->params->username,
'password' => $config->database->params->password,
'dbname' => $config->database->params->dbname
));
$sess_config = array(
'name' => 'session',
'primary' => array(
'session_id',
'save_path',
'name',
),
'primaryAssignment' => array(
'sessionId',
'sessionSavePath',
'sessionName',
),
'modifiedColumn' => 'modified',
'dataColumn' => 'session_data',
'lifetimeColumn' => 'lifetime',
);
Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($sess_config));
//Initialize the session
Zend_Session::start();
config
<?php
// config.php
return array(
'database' => array(
'adapter' => 'Pdo_Mysql',
'params' => array(
'host' => 'localhost',
'username' => 'root',
'password' => '',
'dbname' => 'hol'
)
),
'session' => array(
'name' => 'session',
'primary' => array(
'session_id',
'save_path',
'name',
),
'primaryAssignment' => array(
'sessionId',
'sessionSavePath',
'sessionName',
),
'modifiedColumn' => 'modified',
'dataColumn' => 'session_data',
'lifetimeColumn' => 'lifetime'
)
);
SQL:
CREATE TABLE `session` (
`session_id` char(32) NOT NULL,
`save_path` varchar(32) NOT NULL,
`name` varchar(32) NOT NULL DEFAULT '',
`modified` int,
`lifetime` int,
`session_data` text,
PRIMARY KEY (`Session_ID`, `save_path`, `name`)
);
You didn't post the contents of your config.php, but based on the error I suspect you did not specify an adapter (mysql, pdo, etc).
My config file looks something like (yaml):
database:
adapter: Pdo_Mysql
params:
host: myhost
dbname: mydb
username: myusername
password: mypassword
According to the Zend API docs, you have to specify the adapter like this:
// Set this before you make the call to setSaveHandler()
Zend_Db_Table_Abstract::setDefaultAdapter($db);
Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($sess_config));
You either need to call Zend_Db_Table_Abstract::setDefaultAdapter($db) providing the $db object you created in your configuration example, as it appears you don't have a default DB adapter set up given the error, or you need to add the $db object to the $sess_config array so it gets set up as the DB adapter for Zend_Session.
Zend_Session_SaveHandler_DbTable extends Zend_Db_Table_Abstract and any options unknown to Zend_Session_SaveHandler_DbTable (e.g. database configuration options) are then passed to the constructor of Zend_Db_Table_Abstract which sets up the DbTable.
Try this:
$sess_config = array(
'db' => $db, // Pass the $db adapter as the 'db' parameter to Zend_Db_Table_Abstract
'name' => 'session',
'primary' => array(
'session_id',
'save_path',
'name',
),
'primaryAssignment' => array(
'sessionId',
'sessionSavePath',
'sessionName',
),
'modifiedColumn' => 'modified',
'dataColumn' => 'session_data',
'lifetimeColumn' => 'lifetime',
);