I'm getting this error when I'm trying to edit data using CodeIgniter.
My controller:
public function edit_data($kode_part)
{
$tabel_part = $this->model_tabel_part->get_tabel_part("where kode_part ='$kode_part'");
foreach($tabel_part->result_array()as $row){
$kode_part = $row['kode_part'];
$nama_part = $row['nama_part'];
$warna_part = $row['warna_part'];
$cavity = $row['cavity'];
$gross = $row['gross'];
}
$data['kode_part'] = $kode_part;
$data['nama_part'] = $nama_part;
$data['warna_part'] = $warna_part;
$data['cavity'] = $cavity;
$data['gross'] = $gross;
$this->load->view('datamaster/tabel_part/v_edit_part', $data);
}
My Model:
public function get_tabel_part($where = ""){
$data_tabel_part = $this->db->query("select * from tabel_part".$where);
return $data_tabel_part;
}
And I'm getting this error:
A Database Error Occurred
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '='34232-C0100'' at line 1
select * from tabel_partwhere kode_part ='34232-C0100'
Filename: C:/xampp/htdocs/tpidbv1.1/system/database/DB_driver.php
Line Number: 691
Can you find any thing wrong here?
Your Error message is this...
select * from tabel_partwhere kode_part ='34232-C0100'
There is No Space between the table name and your "where" statement.
So in your model you need to add in a space in your SQL...
So this...
$data_tabel_part = $this->db->query("select * from tabel_part".$where);
Becomes this...
$data_tabel_part = $this->db->query("select * from tabel_part ".$where); // Added Space
Please add a space between the table name and the where clause.
public function get_tabel_part($where = ""){
$data_tabel_part = $this->db->query("select * from tabel_part ".$where);
return $data_tabel_part;
}
Related
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?
I am using codeigniter activerecord and I am fetching information of 2 many to many table but undefined index is appearing in my error log in the CI view
public function editCommission($data){
$this->db->select('client_user_cashin.id, client.account_name, property.property_name, client.unit_number, client.reservation_date, users.givenname, users.surname, client_user.sl_rate, sl_position.position, cash_in.cash_recieved, comm_status.comm_status, computation_type.com_type');
$this->db->from('client_user_cashin');
$this->db->join('client_user', 'client_user.id = client_user_cashin.client_user_id');
$this->db->join('client', 'client.id = client_user.client_id');
$this->db->join('property_commision', 'property_commision.id = client.property_commision_id');
$this->db->join('property', 'property.id = client.property_id');
$this->db->join('users', 'users.id = client_user.user_id');
$this->db->join('sl_position', 'sl_position.id = client_user.sl_position_id');
$this->db->join('cash_in', 'cash_in.id = client_user_cashin.cash_in_id');
$this->db->join('comm_status', 'comm_status.id = client_user_cashin.comm_status_id');
$this->db->join('computation_type', 'computation_type.id = cash_in.comp_type_id');
$this->db->order_by('client_user_cashin.id');
$query = $this->db->get();
return $query->result_array();
}
Fetch the data in the edit form
Just apply left-join on all the joins like
$this->db->join('client_user', 'client_user.id = client_user_cashin.client_user_id','left');
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
I have this save method in my model:
public function save($data = null, $whiteList = null){
$res = false;
$sql = '';
$di = \Phalcon\DI::getDefault();
try {
$param = array("[fecha] = to_date('" . $this->fecha . "', 'YYYY-MM-DD HH24:MI:SS') and [parametro_id] = :parametro_id:",
"bind" => array("parametro_id" => $this->parametro_id) );
$primero = Instantaneos::findFirst($param);
if ($primero){
$this->instantaneo_id = $primero->instantaneo_id;
} else {
$sql = "select AZUL_S_INSTANTANEOS.nextval from dual";
$result = $di->getShared('db')->query($sql);
while($row = $result->fetchArray()){
$this->instantaneo_id = $row['NEXTVAL'];
}
}
$this->fecha = date('d/M/y', strtotime($this->fecha));
$res = parent::save($data, $whiteList);
$res = true;
} catch (Exception $ex) {
$res = false;
$this->appendMessage(new Message($ex->getMessage()));
}
return $res;
}
And it works, but, when I modify this line:
$this->fecha = date('d/M/y', strtotime($this->fecha));
With this one:
$this->fecha = date('d/M/y H:i:s', strtotime($this->fecha));
I get this error:
SQLSTATE[HY000]: General error: 1830 OCIStmtExecute: ORA-01830: date format picture ends before converting entire input string
(ext\pdo_oci\oci_statement.c:148)
And I need to save the time information, I try to make my own save method, with no parent::save, writing my own sql when insert or update:
$sql_i = "insert into AZUL_INSTANTANEOS values(%d,%d,to_date('%s', 'YYYY-MM-DD HH24:MI:SS'),%f,'%s')";
$sql_u = "update AZUL_INSTANTANEOS set val = %f, valf = '%s' where instantaneo_id = %d";
And using:
$db->execute($sql);
But I get another error:
Maximum execution time of 30 seconds exceeded in <b>\app\config\services.php</b> on line <b>172</b><br />
I'm using:
XAMPP 1.8.2 (PHP Version 5.4.31, Apache/2.4.10 (Win32))
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
Phalcon 2.1.0b
¿Any advice?, thx.
Oracle is not fully supported in Phalcon. There is a driver in the incubator located here that you can utilize.
Oracle also has a different syntax that Phalcon's PHQL potentially cannot recognize.
I would suggest you start by adding SQL statement logging to your application, so that you can see what is being sent to the database and then figure out how to correct it.
Have a look at this page and scroll down to where it says Logging SQL Statements
Add that and have a look at what is going on with your query.
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.