using (-) dash in mysql table name - mysql

There is an error while i want to backup my database
A Database Error Occurred
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 '-01-000001' at line 1
SELECT * FROM temp_01-01-000001
Filename: F:\xampp\htdocs\erp_zaara\system\database\DB_driver.php
Line Number: 330
Is there any way to solve this prob with the table name (temp_01-01-000001).

You have to add quotes as your table name contains number. I think the following query will work.
SELECT * FROM `temp_01-01-000001`

You could edit line 132 of the file /system/database/drivers/mysql/mysql_utility.php
From:
$query = $this->db->query("SELECT * FROM $table");
To:
$query = $this->db->query("SELECT * FROM `$table`");

Related

MySQL syntax error when using sqlite3 query

I just wanted to switch from sqlite3 to using MySQL but I get errors in this query:
SELECT
metapp_notif.id,
name,
age,
place,
note,
metapp_notif.lat,
metapp_notif.longt,
haslatlong,
dati,
ntype,
grpm_id,
image,
send_id,
pro.latitude,
pro.longtitude,
metapp_notif.dati,
metapp_notif.activity
FROM (metapp_notif
join (metapp_profil
join metapp_userlocation
ON metapp_profil.user_id = metapp_userlocation.user_id) AS pro
ON metapp_notif.send_id = pro.user_id)
WHERE metapp_notif.rec_id =% d;
I'm getting this error:
ERROR 1064 (42000): 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 'pro on metapp_notif.send_id=pro.user_id) where
metapp_notif.rec_id=2' at line 1
I was searching for differences between sqlite3 and mysql but can't figure out what is wrong.
Thanks in advance!
Try this syntax in Mysql
SELECT metapp_notif.id,
name,
age,
place,
note,
metapp_notif.lat,
metapp_notif.longt,
haslatlong,
dati,
ntype,
grpm_id,
image,
send_id,
latitude,
longtitude,
metapp_notif.dati,
metapp_notif.activity
FROM metapp_profil
join metapp_notif
ON metapp_notif.send_id = metapp_profil.user_id
join metapp_userlocation
ON metapp_profil.user_id = metapp_userlocation.user_id
WHERE metapp_notif.rec_id like '% d'; -- Not sure what you are trying to do here

How to specify named parameter value for NOT IN clause in MySQL query?

I have written the following SQL query:
$media_category_ids = array( 11, 12);
$params = array();
$sql = "SELECT `id`
FROM query
WHERE 1=1
AND WHERE query.media_category_id NOT IN (:media_category_ids)";
$params['media_category_ids'] = implode(",",$media_category_ids);
$prepared_query = $c->prepare($sql);
$prepared_query->execute($params);
However I can't seem to get the syntax for the named parameter in the 'NOT IN' clause correct as I get the following error:
Message: An exception occurred while executing 'SELECT `id` FROM query WHERE 1=1 AND WHERE query.media_category_id NOT IN (:media_category_ids)': SQLSTATE[42000]: Syntax error or access violation: 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 'WHERE query.media_category_id NOT IN ('11,2')' at line 4
Really appreciate it if someone can point me in the right direction.
Remove additional WHERE after AND operator
AND WHERE query.media_category_id
^here
Use following query, no another WHERE needed:
SELECT `id`
FROM query
WHERE 1=1
AND query.media_category_id NOT IN (:media_category_ids)

MySQL _ Retrieve multiple rows and columns in single query

am new to Mysql
I want to retrieve all the columns containing StrainName=M18 from the database , but am getting error. please help me in this
SELECT *
strain.strainName,
feature.contigId,
feature.startPosition,
feature.stopPosition,
feature.orfId,
feature.orfType,
feature.funcClassification,
feature.rastId,
feature.strand
from feature,strain
where feature.id=strain.id and strainName='M18';
ERROR 1064 (42000): 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 'strain.strainName,feature.contigId,feature.startPosition,feature.stopPosition,fe' at line 1
you need add comma after *
SELECT *, -- <<====== HERE
strain.strainName,
feature.contigId,
feature.startPosition,
feature.stopPosition,
feature.orfId,
feature.orfType,
feature.funcClassification,
feature.rastId,
feature.strand
from feature,strain
where feature.id=strain.id and
strainName='M18';
to get all columns:
SELECT * from feature,strain
where feature.id=strain.id and strainName='M18';
to get specific columns :
SELECT
strain.strainName,
feature.contigId,
feature.startPosition,
feature.stopPosition,
feature.orfId,
feature.orfType,
feature.funcClassification,
feature.rastId,
feature.strand
from feature,strain
where feature.id=strain.id and
strainName='M18';

MySQL Syntax With Simple Joins

I'm having trouble figuring out why this query does not work. Names have been sanitized as this is proprietary code.
QRY:
SELECT l.albert, o.ben, m.caleb, m.dennis, m.edgar
FROM octopus o, lorax l, monkey m
WHERE o.ben = l.ben
AND l.franklin= m.franklin
AND o.ben= :ben
ORDER BY l.albert DESC
LIMIT 1
Here is the error that I get:
MySQL 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 'QRY: SELECT l.albert, o.ben, m.caleb, m.dennis, m' at line 1
It seems like you have
"QRY: "
at the beginning of your query. It should start with
"SELECT ...

#1064 When Deleting item from Table

I recently upgraded to MYSQL 5. That is latest version that webhost allows. When trying to update a table or delete an entry this is the error I receive while in phpmyadmin.
Error
There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problem
ERROR: Unclosed quote # 101
STR: '
SQL: DELETE FROM inmates WHERE inmates.counties_id = 33 AND CONVERT(inmates.link USING utf8) = \'http://inmate1.riversidesheriff.org/iis/\' LIMIT 1
SQL query:
DELETE FROM inmates
WHERE `inmates`.`counties_id` = 33
AND CONVERT(`inmates`.`link` USING utf8) = \'http://inmate1.riversidesheriff.org/iis/\'
LIMIT 1
MySQL said:
Documentation #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 '\'http://inmate1.riversidesheriff.org/iis/\' LIMIT
1' at line 1
and here is the query
SELECT * FROM `inmates` WHERE 1
any help is greatly appreciated
thank you.
Lose the backslash before the single-quotes: they are not required.
By that I mean, change this:
\'http://inmate1.riversidesheriff.org/iis/\'
To this:
'http://inmate1.riversidesheriff.org/iis/'