Zend Framework Multi Database issue - database

application.ini
resources.multidb.db1.adapter = "pdo_mysql"
resources.multidb.db1.host = "localhost"
resources.multidb.db1.username = "root"
resources.multidb.db1.password = "root"
resources.multidb.db1.charset = "utf8"
resources.multidb.db1.dbname = "admin"
resources.multidb.db2.adapter = "pdo_mysql"
resources.multidb.db2.host = "localhost"
resources.multidb.db2.username = "root"
resources.multidb.db2.password = "root"
resources.multidb.db2.dbname = "hp"
resources.multidb.db2.charset = "utf8"
resources.multidb.db2.default = true
Bootstrap.php:
protected function _initDb(){
$resources = $this->getPluginResources('multidb');
Zend_Registry::set('db1', $resource->getDb('db1'));
Zend_Registry::set('db2', $resource->getDb('db2'));
}
class methods:
Array
(
[0] => _initDb
[1] => _initPrefix
[2] => _initSession
[3] => _initRouters
[4] => _initAutoloader
[5] => _initControllerHelper
[6] => __construct
[7] => run
[8] => setResourceLoader
[9] => getResourceLoader
[10] => getAppNamespace
[11] => setAppNamespace
[12] => setOptions
[13] => getOptions
[14] => hasOption
[15] => getOption
[16] => mergeOptions
[17] => getClassResources
[18] => getClassResourceNames
[19] => registerPluginResource
[20] => unregisterPluginResource
[21] => hasPluginResource
[22] => getPluginResource
[23] => getPluginResources
[24] => getPluginResourceNames
[25] => setPluginLoader
[26] => getPluginLoader
[27] => setApplication
[28] => getApplication
[29] => getEnvironment
[30] => setContainer
[31] => getContainer
[32] => hasResource
[33] => getResource
[34] => __get
[35] => __isset
[36] => bootstrap
[37] => __call
[38] => _bootstrap
[39] => _executeResource
[40] => _loadPluginResource
[41] => _markRun
[42] => _resolvePluginResourceName
)
When i run application, its return error: Call to a member function getDb() on a non-object.
Can anyone help me?
Thanks!
Sorry my English is bad.

You had typo in your function -
protected function _initDb(){
$resources = $this->getPluginResources('multidb');
// changed $resource to $resources
Zend_Registry::set('db1', $resources->getDb('db1'));
Zend_Registry::set('db2', $resources->getDb('db2'));
}

Related

display specific index multidimensional array

i have an multidimensional array like this, but i just only need some index to be displayed,
Array
Array
(
[0] => Array
(
[1] => 220
[38] => 200
[232] => 970
)
[1] => Array
(
[0] => 220
[2] => 190
[39] => 200
)
[2] => Array
(
[1] => 190
[3] => 40
[50] => 220
)
[3] => Array
(
[2] => 40
[4] => 200
[57] => 120
)
)
then i just want to display only index [1] and [3], so it would be like this
Array
(
[1] => Array
(
[0] => 220
[2] => 190
[39] => 200
)
[3] => Array
(
[2] => 40
[4] => 200
[57] => 120
)
)
i try using this code
$order = array(1,3);
uksort($graph, function($key1, $key2) use ($order) {
return (array_search($key1, $order) > array_search($key2, $order));
});
but still, its displayed the rest array that i dont need it that's key [0] and [2]
Like this:
foreach(array_keys($graph) as $key)
{
if($key == 0|| $key == 2)
{
unset($graph[$key]);
}
}
print_r
Array
(
[1] => Array
(
[0] => 220
[2] => 190
[39] => 200
)
[3] => Array
(
[2] => 40
[4] => 200
[57] => 120
)
)

Merge two arrays like this

I have two array like this::
$doctor = Array(
[0] => 4
[1] => 5
[2] => 8
[3] => 35
[4] => 41
[5] => 42
)
$clinic = Array(
[0] => 1
[1] => 3
[2] => 9
[3] => 15
[4] => 19
[5] => 20
)
Now i want to add these array like this
$all = array(
[0] => 4
[1] => 1
[2] => 5
[3] => 3
[4] => 8
[5] => 9
[6] => 35
[7] => 15
[8] => 41
[9] => 19
[10] => 42
[11] => 20
I have tried this but it is not my expected output:
$all = array_merge( $doctor , $clinic );
Any solution?
Thanks
You can use for loop to do that
$all=[];
for($i=0;$i<6;$i++){
$all[]=$doctor[$i];
$all[]=$clinic[$i];
}
if you don't have same length for the arrays,
Try
$doctor_size=sizeof($doctor);
$clinic_size=sizeof($clinic);
$all=[];
$size=$doctor_size;
if($doctor_size<$clinic_size){
$size=$clinic_size;
}
for($i=0;$i<$size;$i++){
if(isset($doctor[$i])){
$all[]=$doctor[$i];
}
if(isset($clinic[$i])){
$all[]=$clinic[$i];
}
}

SQL Server : error insert query

I have an issue with a SQL Server column quote number which not accept more than 5 digits. 5 digits or below it is working fine, but above 5 digits, it is causing an error:
xx.xx.xx.xx didn’t send any data.
ERR_EMPTY_RESPONSE
Example - quote number 12345 is working fine, but 123456 causes the error.
I have also changed bindParam to bindValue in query but not result.
Connection:
try {
$proconn = new PDO("dblib:host=$servername;dbname=TableQuote;charset=UTF-8", $username, $password);
// set the PDO error mode to exception
$proconn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e)
{
echo "Connection failed" . $e->getMessage;
}
Variable data:
//$quote_number="123456";
[quote_noumber] => '12345'
[inside_sales] => 'Pat Zerphy'
[outside_sales] => 'SEL102'
[customer_code] => 'SEL101'
[custome_name] => 'Selex Systems Inegrations'
[customer_contact] => 'Bob Smith'
[quote_details] => 'Misc coax cable assemblies.
1/2" Superflex, 1/4" Superflex'
[rna_location] => '1'
[number_of_line_items] => '25'
[created] => '1468291705'
Insert query:
try {
$prosql = $proconn->prepare("insert into dbo.QuoteRecord(quote_number,customer_code,customer_name,rna_location,inside_sale,outside_sale,customer_contact,quote_detail,number_of_line_items,created)VALUES(:quote_number,:customer_code,:customer_name,:rna_location,:inside_sale,:outside_sale,:customer_contact,:quote_detail,:number_of_line_items,:created)");
$prosql->bindParam(':quote_number',$quote_number);
$prosql->bindParam(':customer_code',$customer_code);
$prosql->bindParam(':customer_name',$customer_name);
$prosql->bindParam(':rna_location',$rna_location);
$prosql->bindParam(':inside_sale',$inside_sale);
$prosql->bindParam(':outside_sale',$outside_sale);
$prosql->bindParam(':customer_contact',$customer_contact);
$prosql->bindParam(':quote_detail',$quote_detail);
$prosql->bindParam(':number_of_line_items',$number_of_line_items);
$prosql->bindParam(':created',$created);
$prosql->execute();
}
catch ( PDOException $e ) {
print( "Error connecting to SQL Server." );
die(print_r($e));
}
Data types:
Array
(
[TABLE_CATALOG] => TableQuote
[0] => proALPHA
[TABLE_SCHEMA] => dbo
[1] => dbo
[TABLE_NAME] => QuoteRecord
[2] => QuoteRecord
[COLUMN_NAME] => quote_number
[3] => quote_number
[ORDINAL_POSITION] => 2
[4] => 2
[COLUMN_DEFAULT] =>
[5] =>
[IS_NULLABLE] => YES
[6] => YES
[DATA_TYPE] => varchar
[7] => varchar
[CHARACTER_MAXIMUM_LENGTH] => 128
[8] => 128
[CHARACTER_OCTET_LENGTH] => 128
[9] => 128
[NUMERIC_PRECISION] =>
[10] =>
[NUMERIC_PRECISION_RADIX] =>
[11] =>
[NUMERIC_SCALE] =>
[12] =>
[DATETIME_PRECISION] =>
[13] =>
[CHARACTER_SET_CATALOG] =>
[14] =>
[CHARACTER_SET_SCHEMA] =>
[15] =>
[CHARACTER_SET_NAME] => iso_1
[16] => iso_1
[COLLATION_CATALOG] =>
[17] =>
[COLLATION_SCHEMA] =>
[18] =>
[COLLATION_NAME] => SQL_Latin1_General_CP1_CI_AS
[19] => SQL_Latin1_General_CP1_CI_AS
[DOMAIN_CATALOG] =>
[20] =>
[DOMAIN_SCHEMA] =>
[21] =>
[DOMAIN_NAME] =>
[22] =>
)
Example - quote number - 12345 working fine but 123456 it giving
error.
if that's the case then most probably it's because of the column size definition for column quote_number. Looks like it's a VARCHAR column and if it is still not wrong you have set its size to VARCHAR(5) probably.
Post your table definition or schema for dbo.QuoteRecord table.

Getting nids using entityfieldquery

I want to get all the nids but I am unable to get them. Below is my snippet.
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node');
$query->entityCondition('bundle', 'product');
$query->propertyCondition('status', 1);
$query->fieldCondition('field_product_sub_cat', 'tid',array($leaf_nodes));
$query->range(0, 10);
$result = $query->execute();
if (isset($result['node']))
{
$product_childnid = array_keys($result['node']);
}
Below is my result:UPDATED
Array
(
[node] => Array
(
[78] => stdClass Object
(
[nid] => 78
[vid] => 78
[type] => product
)
[80] => stdClass Object
(
[nid] => 80
[vid] => 80
[type] => product
)
[82] => stdClass Object
(
[nid] => 82
[vid] => 82
[type] => product
)
[84] => stdClass Object
(
[nid] => 84
[vid] => 84
[type] => product
)
[86] => stdClass Object
(
[nid] => 86
[vid] => 86
[type] => product
)
[88] => stdClass Object
(
[nid] => 88
[vid] => 88
[type] => product
)
[90] => stdClass Object
(
[nid] => 90
[vid] => 90
[type] => product
)
[92] => stdClass Object
(
[nid] => 92
[vid] => 92
[type] => product
)
[94] => stdClass Object
(
[nid] => 94
[vid] => 94
[type] => product
)
[100] => stdClass Object
(
[nid] => 100
[vid] => 100
[type] => product
)
)
)
then below code is providing me all the paths too,
$paths = array();
if (isset($result['node']))
{
foreach($result['node'] as $key => $node)
{
$paths[$node->nid] = drupal_get_path_alias("node/$node->nid");
}
}
now the next problem is how can I represent these paths in my anchor tag?Because they all are in an array.Below is my array structure of paths aliases:
Array
(
[78] => equivalent-fireman-glove-details
[80] => toughguard®-2
[82] => toughguard®-3
[84] => toughguard-®sizzler®
[86] => tough-guard-®
[88] => kevlar®-double-glove
[90] => nomex®-industrial-coverall
[92] => tough-guard®-clinker®-0
[94] => lab-coats-sa-nlc
)
and below is an array structure data to link with above paths:
Array
(
[0] => 71
[1] => 73
[2] => 81
[3] => 83
[4] => 85
[5] => 87
[6] => 89
[7] => 91
[8] => 93
)
Try this:
$query->fieldCondition('field_product_sub_cat', 'tid',array($leaf_nodes),'IN');
So that the query in compare value with array.

PHP Divide Array By Empty Value

This is an array from input field as below
Array(
[0] =>
[1] => 737
[2] => 736
[3] => 735
[4] =>
[5] => 748
[7] => 744
[8] => 747
[9] => 746
[10] =>
[11] => 748
[12] => 747
[13] => 746
[14] => 745
[15] => 744
);
Is there a way to divide it by empty value and removing the empty value as below:
Array(
[0] => Array(
[0] => 737
[1] => 736
[2] => 735
)
[1] => Array(
[0] => 748
[1] => 744
[2] => 747
[3] => 746
)
[2] => Array(
[0] => 748
[1] => 747
[2] => 746
[3] => 745
[4] => 744
)
)
If you want to split the array into sub-arrays with the "null" values as delimiters, something like that should do the job:
$newArray = array();
$subArray = null;
for ($i = 0; $i < count($array); $i++) {
if (!$subArray) $subArray = array();
$v = $array[$i];
if ($v) {
array_push($subArray, $v);
} else {
if (count($subArray) > 0) array_push($newArray, $subArray);
$subArray = null;
}
}
if ($subArray) array_push($newArray, $subArray);

Resources