I have this in my code and im using codeigniter yet it's producing an error
// make call to db and create a file
$this->db->select("*");
$this->db->from("mst_global_settings mgs");
$this->db->join("trans_global_settings tgs", "mgs.global_name_id=tgs.global_name_id", "inner");
$this->db->where('`tgs`.lang_id', $lang_id);
$query = $this->db->get();
$result = $query->result_array();
$tmp_array = array();
foreach ($result as $global_array) {
$tmp_array[$global_array["name"]] = $global_array["value"];
}
Codeigniter is giving me the following error
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'tgs`.`lang_id` = 'en'' at line 4
SELECT * FROM (`p931_mst_global_settings` mgs) INNER JOIN `p931_trans_global_settings` tgs ON `mgs`.`global_name_id`=`tgs`.`global_name_id` WHERE `p931_`tgs`.`lang_id` = 'en'
Filename: /models/mdl_common.php
Line Number: 26
The problem is your single quotes.
Change this:
$this->db->where('`tgs`.lang_id', $lang_id);
To this:
$this->db->where('tgs.lang_id', $lang_id);
Related
I am getting internal server error 500 when I pass this query inside my Laravel controller. Is there any alternative to write this?
$var1 = $request->xyz;
$var2 = $request->abc;
$take = $request->take;
$skip = $request->skip;
$sample = DB::table('table_name')
->select('table_name.*', DB::raw('COUNT(column_name) as total_count'))
->where('column_name1', $var1)
->where('column_name2', $var2)
->offset($skip)
->limit($take)
->get();
$encrypted = AESEncrypt($sample);
return json_encode($encrypted);
try to use ->select('column_name', DB::raw('COUNT(*) as total_count'))
and also try \DB::
I've built a powershell script that allows me to run and email the result of sql queries that are being read from a sql file:
function global:readscript($path)
{
#using UTF7 encoding to allow select with accented/french/russian/chinese/... etc chars
$inenc = [System.Text.Encoding]::UTF7
$reader = new-object System.IO.StreamReader($path, $inenc)
$finalquery = ""
while ($line = $reader.ReadLine())
{
$finalquery += $line
}
$reader.close()
return $finalquery
}
function global:get-result($query)
{
$oracleconnection = new-object Oracle.ManagedDataAccess.Client.OracleConnection
$oracleconnection.connectionstring = $connectionstring
$oracleconnection.Open()
$oraclecommand = $oracleconnection.CreateCommand()
$oraclecommand.CommandText = $query
$reader = $oraclecommand.ExecuteReader()
#...etc
}
$scriptquery = readscript "d:\mysqlquery.sql"
get-result($scriptquery)
Everything is working fine so far, except this one sql script that contains the "+" sign for purpose of calculation.
Lets say file mysqlquery.sql contains a line such as:
(SELECT COUNT(a.ID)) + (SELECT COUNT(b.ID))
I can see in the console it's being translated to
(SELECT COUNT(a.ID)) (SELECT COUNT(b.ID))
and of course throws this annoying exception "missing right parenthesis"
How do I escape this plus sign when reading it from a txt file ?
On local PC this works.
$HmsDBuser = 'test';
$HmsDBpassword = 'password';
$HmsDBserver = 'Developer,1433';
$HmsDBdatabase = 'DBNAME';
$this->db = new PDO ("sqlsrv:Server=$HmsDBserver;Database=$HmsDBdatabase","$HmsDBuser","$HmsDBpassword", array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
My Slim Framework is on Server A: 121.55.0.25
My database is on another Server B: 121.55.0.21
$HmsDBuser = 'test';
$HmsDBpassword = 'password';
$HmsDBserver = '121.55.0.21\MYSERVER\MSSQLSERVER,1433';
$HmsDBdatabase = 'DBNAME';
$this->db = new PDO ("sqlsrv:Server=$HmsDBserver;Database=$HmsDBdatabase","$HmsDBuser","$HmsDBpassword", array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
and after I connect to the database, I call function with path "product" in Slim framework.
ERROR got on Console :
angular.js:8619 GET http://121.55.0.25/product-manager_servertest/api/v1/products 404 (Not Found)
Try it like this:
$HmsDBserver = '121.55.0.21\\MYSERVER\\MSSQLSERVER,1433';
Notes:
Escaped backslashes.
No space before port.
If it doesn't work, then use just the server name, like this:
$HmsDBserver = '<server-name>,1433';
$datos = explode(';',$linea);
$product_ean = trim($datos[0]);
$product_price = trim($datos[1]);
$name_es = trim($datos[2]);
$short_description_es = trim($datos[3]);
echo $product_ean,'<br>';
echo $product_price,'<br>';
echo $name_es ,'<br>';
echo $short_description_es,'<br>';
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$columns = array('product_id' ,'product_ean', 'product_price', 'name_es-ES', 'short_description_es-ES');
$values = array(NULL, $product_ean, $product_price, $name_es, $short_description_es);
$query
->insert($db->quoteName('vrg_jshopping_products'))
->columns($db->quoteName($columns))
->values(implode(',', $values));
$db->setQuery($query);
$db->execute();
Error displaying the error page: Application Instantiation
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '600,1000,articulo nuevo 1,Articulo de test 1)' at line 3
SQL=INSERT INTO vrg_jshopping_products (product_id,product_ean,product_price,name_es-ES,short_description_es-ES) VALUES (,600,1000,articulo nuevo 1,Articulo de test 1)
You are getting sql error because you have not quoted your values.You can use below code.
$columns = array('product_id' ,'product_ean', 'product_price', 'name_es-ES', 'short_description_es-ES');
$values = array(NULL, $product_ean, $product_price, $name_es, $short_description_es);
// Prepare the insert query.
$query
->insert($db->quoteName($table))
->columns($db->quoteName($columns))
->values(implode(',', $db->quote($values)));
I am using the simplest controller and model as shown here:
http://book.cakephp.org/view/1341/Basic-Usage
But when i go to www.mysite.com/categories
the code that causes it is:
<?php
class CategoriesController extends AppController {
var $name = 'Categories';
function index() {
$this->data = $this->Category->generatetreelist(null, null, null, ' ');
debug ($this->data); die;
}
}
?>
i get the following error:
Warning (512): SQL Error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'recover' at line 1 [CORE/cake/libs/model/datasources/dbo_source.php, line 684]
Code | Context
$out = null;
if ($error) {
trigger_error('<span style="color:Red;text-align:left"><b>' . __('SQL Error:', true) . "</b> {$this->error}</span>", E_USER_WARNING);
$sql = "recover"
$error = "1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'recover' at line 1"
$out = null
DboSource::showQuery() - CORE/cake/libs/model/datasources/dbo_source.php, line 684
DboSource::execute() - CORE/cake/libs/model/datasources/dbo_source.php, line 266
DboSource::fetchAll() - CORE/cake/libs/model/datasources/dbo_source.php, line 410
DboSource::query() - CORE/cake/libs/model/datasources/dbo_source.php, line 364
Model::call__() - CORE/cake/libs/model/model.php, line 502
Overloadable::__call() - CORE/cake/libs/overloadable_php5.php, line 50
AppModel::recover() - [internal], line ??
CategoriesController::index() - APP/controllers/categories_controller.php, line 7
Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 204
Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 171
[main] - APP/webroot/index.php, line 83
Query: recover
app/controllers/categories_controller.php (line 8)
I am totally confused, since I just copy-pasted from the original cakephp cookbook tutorial.
I have:
controllers/categories_controller.php
models/category_model.php
and the code is copy paste from the tutorial.
Any help?
Problem solved. Misnaming the model file.
It Was: category_model.php
Should have been: category.php =(
Have you created the Category Model?
I am not sure but I belive you should tell the controller which model u intend to use by specifying:
var $name = 'Categories';
var $uses = array("Category");
function index() {
$this->data = $this->Category->generatetreelist(null, null, null, ' ');
debug ($this->data); die;
}