How to Change the Database Source from within an application - xampp

I'm developing an app on xammp that allows you add multiple schools, and with each new school added, a new database is added. All that works fine.
The issue is in switching from database name to another database name in my db config. I have a form action "set_source" that triggers the setDBNAME action but get an uncaught error.
I tried the following code
class dbConfig
{
public $hostname = 'localhost'; //hostname for db connection
public $username = 'root'; // username for db connection
public $password = 'password'; //password for db conection
public $dbname = 'school1'; //this must be dynamically changeable
public $mysqli;
function setDBNAME($id)
{
$sql = "SELECT `school_name`, `subdomain`, `selected`, `url` FROM board.school WHERE school_id = $id AND selected = 'True'";
$data = $this->mysqli->execute_query($sql); //line triggering error
if($data) {
return new dbConfig(localhost, root, password, $data['url']);
}
else {
return null;
}
}
}
But Got the following error
Fatal error: Uncaught Error: Call to a member function execute_query()
on null in path\to\file\dbConfig.php:15 Stack trace: #0 path\to
\file\myaccountController.php(50): dbConfig->setDBNAME('1') #1
path\to\file\Controller11.php(29): myaccountController->set_source()
#2 path\to\file\myaccount.php(20): Controller11->run() #3 {main}
thrown in path\to\file\dbConfig.php on line 15
Any pointers and or solutions will be muchos gracias

Related

MODELS: Cannot update values in DB

I have this function to update the DB values, but one of the statements is not working. I created a relation to the table called ventas, however, it is not updating it´s value to NULL. This is my code:
public function cambiarEstatusFactura( Request $request){
try{
\DB::beginTransaction();
$factura = FacturaVenta::with('venta')->where( 'id' , $request->id )->first();
// dd('Esto : ' , $factura->venta->factura_uuid);
if( $factura->estatus == 'Timbrada' ){
$factura->estatus = 'Cancelada';
$factura->uuid = NULL;
$factura->venta->factura_uuid = NULL;
$factura->save();
}
\DB::commit();
}catch (Exception $e){
\Alert::error($e->getMessage())->flash();
return redirect('admin/finanzas/factura/venta');
}
}
The statement that is not working is:
$factura->venta->factura_uuid = NULL;
Though the other statements work seamlessly, this seems to have issues but I do not get any error messages.
Variable $factura contains FacturaVenta model and the relation venta brings the model from the table ventas, that's why I try to access to it via $factura->venta and the commented dd('Esto : ' , $factura->venta->factura_uuid); in the code brings the value correctly, that means that it's pointing correctly to the correct table but it's not being updated to NULL.
I just want to update the value from whatever it has to NULL.
Could you help me please?

Create a custom login in wakanda 1.1.3

I am creating a Angular2 application in which i need a custom login instead of the existing directory login So, I added the following code and created some new files and code as the following
i added a new file login.js under the backend location with the following code
directory.setLoginListener("loginFuction","Admin");
I made changes to my require.js as the following
function loginFunction(email,password){
console.log("Call is being made to the backend");
var u = ds.User.find("email : 1" ,email);
console.log(u);
if(!u){
return false;
}else{
var token = currentSession.promoteWith("Admin");
if(u.password == password){
var theGroups = [];
switch(u.role){
case 'Admin':
theGroups.push('Admin');
break;
case 'Users':
theGroups.push('Users');
break;
}
var connectTime = new Date();
return {
ID : u.ID,
name : u.email,
fullName : u. fullname,
belongsTo : theGroups,
storage:{
time : connectTime
}
};
}else{
return {
error : 1024,
errorMessage : "invalid login"
}
}
}
};
when i call the loginFunction from my normal component like
this.wakanda.directory.login('adithya#gmail.com','adithya').then(res => {
console.log(res);
});
I am getting an error stating
EXCEPTION: Uncaught (in promise): Error: Directory.login: Unauthorized
All the table are being made global access, and everything is being made as public.
Can anyone help me with this solution.
Thanks in advance.
The exact method of creating the custom login in wakanda studio 1.1.3 is of the following we have to make change in the function call present in the bootstrap.js like the following
directory.setLoginListener("loginFunction");
by removing the "Admin" as the second parameter .

Doctrine is converting string to hex value

I am converting one database to another database through a script.
While running the script I am getting the following error:
SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xBFbangl...' for column 'country' at row 1
An exception is thrown where it shows that it tries to set country as "\xcf\xbb\xbf\x62\x61\x6e\x67\x6c\x61\x64\x65\x73\x68".
When I var_dump the value, it just shows as "Bangladesh".
Is there something I have to adjust in my php code?
I have tried this, but phpmyadmin is throwing an #1064 error stating a syntax error in the query.
UPDATE
The scripts is a command in Symfony3:
<?php
namespace My\Bundle\Command;
use My\AccommodationBundle\Entity\Visit;
use My\NewAccommodationBundleV2\Entity\Visit as Visit2;
use My\OtherBundle\Entity\Person;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class VisitConvertToNewFormatCommand extends ContainerAwareCommand
{
private $em;
protected function configure()
{
$this
->setName('accommodation:visit:convert')
->setDescription("Converting old structure to new structure'")
;
}
protected function getTimeStamp() {
$currentTime = new \DateTime('now');
return '['.$currentTime->format('Y-m-d H:i:s').'] ';
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln($this->getTimeStamp().$this->getDescription());
$this->em = $this->getContainer()->get('doctrine')->getManager();
$visits = $this->em->getRepository('MyOldAccommodationBundle:Visit')->findAll();
foreach ($visits as $visit) {
$visit2 = new Visit2();
$visit2->setArrivalDate($visit->getArrivalDate());
$visit2->setArrivalStatus($visit->getArrivalStatus());
$visit2->setArrivalTime($visit->getArrivalTime());
$visit2->setBookingType($visit->getBookingType());
$visit2->setCountry($visit->getCountry()); // <----
...
$this->em->persist($visit2);
$user = $visit->getUser();
if ($user != null) {
$person = new Person();
...
$person->setFirstName(trim(ucfirst(strtolower($user->getFirstName()))));
$person->setLastName(trim(ucfirst(strtolower($user->getLastName()))));
$person->setEmail(preg_replace('/\s+/', '', $user->getEmail()));
...
$this->em->persist($person);
}
}
}
}
\x62\x61\x6e\x67\x6c\x61\x64\x65\x73\x68 is Bangladesh; the \xcf\xbb\xbf before it makes no sense. In latin1 it is Ï»¿. It does not validly convert to utf8. CFBB is ϻ (GREEK SMALL LETTER SAN), but then bf is broken utf8.
I suggest it is coming from the source of the data.
var_dump probably showed nothing because of what device you were displaying it on.
Ok after days of trying this did the trick:
$country = iconv("UTF-8", "ISO-8859-1//IGNORE", $country);
I have no idea why it went wrong in the first place. if anybody knows, please share.

Error in processing entity WorkOrder unable to create entity object

I am receiving the following error calling GetAssetEquipmentOp:
"Error in processing entity WorkOrder unable to create entity object"
Here is the code so far:
public stringType getAssetDescription(string equipmentcode)
{
try
{
// Setup Service Objects
MP0302_GetAssetEquipment_001.GetAssetEquipmentService getservice = new MP0302_GetAssetEquipment_001.GetAssetEquipmentService();
MP0302_GetAssetEquipment_001.MP0302_GetAssetEquipment_001 getrequest = new MP0302_GetAssetEquipment_001.MP0302_GetAssetEquipment_001();
MP0302_GetAssetEquipment_001.MP0302_GetAssetEquipment_001_Result getresult = new MP0302_GetAssetEquipment_001.MP0302_GetAssetEquipment_001_Result();
// Setup Return Object
stringType desc = new stringType();
// Setup Service Parameters
getrequest.ASSETID = new MP0302_GetAssetEquipment_001.EQUIPMENTID_Type();
getrequest.ASSETID.EQUIPMENTCODE = equipmentcode;
getrequest.ASSETID.ORGANIZATIONID = new MP0302_GetAssetEquipment_001.ORGANIZATIONID_Type();
getrequest.ASSETID.ORGANIZATIONID.ORGANIZATIONCODE = _orgCodeBody;
// Setup Datastream Object
Datastream.EWS.Session sess = new Datastream.EWS.Session(_userid, _passwd, _orgCodeHead, _url, _tenant, false);
// Prepare Service Request
sess.PrepareServiceRequest(getservice);
// Call Web Service and get result
getresult = getservice.GetAssetEquipmentOp(getrequest);
// Extract Description
desc.stringValue = getresult.ResultData.AssetEquipment.ASSETID.DESCRIPTION;
desc.errorNum = 0;
// Close Up/Dispose
sess.CompleteServiceRequest(getservice);
sess.Dispose();
// Return value
return desc;
}
catch (Exception ex)
{
stringType errorStringType = new stringType();
errorStringType.errorNum = 1;
errorStringType.errorDesc = ex.Message;
return errorStringType;
}
}
I have checked the following:
- User group has interface permissions including BECONN
- User has "Connector" option selected
- User has status authorizations including * to Q for EVNT
Any help would be appreciated.
Problem solved! The problem was that the work order number did not exist. It is a very misleading error but once an existing work order was tested, it fetched the work order with no issues.

An object with the same key already exists in the ObjectStateManage

I have a repository model method:-
public void InsertOrUpdateServer(TMSServer server, string username,long assetid)
{
var resource = GetResourceDetials(assetid);
if (server.ServerID == default(int))
{
//code goes here>>>>>>>>.......>>>
}
else
{
// Existing entity
var auditinfo = IntiateAudit(
tms.AuditActions.SingleOrDefault(
a => a.Name.ToUpper() == "EDIT").ActionID,
tms.TechnologyTypes.SingleOrDefault(
a => a.Name.ToUpper() == "Server").AssetTypeID,
username, server.ServerID
);
server.IT360SiteID = resource.SITEID.Value;
tms.Entry(server).State = EntityState.Modified; // this will raise the esception
InsertOrUpdateAudit(auditinfo);
}
}
but when this method is call i will get the folloiwng exception on :-
tms.Entry(server).State = EntityState.Modified;
An object with the same key already exists in the ObjectStateManager.
The ObjectStateManager cannot track multiple objects with the same
key. Description: An unhandled exception occurred during the
execution of the current web request. Please review the stack trace
for more information about the error and where it originated in the
code.
Exception Details: System.InvalidOperationException: An object with
the same key already exists in the ObjectStateManager. The
ObjectStateManager cannot track multiple objects with the same key.
Source Error: Line 1046: username, server.ServerID);
Line 1047: server.IT360SiteID =
resource.SITEID.Value;///// Line 1048:
tms.Entry(server).State = EntityState.Modified; Line 1049:
// tms.Entry(technologyIP).State = EntityState.Modified; Line 1050:
InsertOrUpdateAudit(auditinfo);
So i can not figure out what is causing this isssue , since i am only tracking one object named servev ?? can anyone advice on what is going on ?

Resources