Right Syntax to Use Near ''

The right syntax to use near 'Name= ?'

It looks to me like the SQL string produced by your code will be

SELECT Id, Data, Role, Name FROM funcionaries WHERE 1=1 Name= ?

Whereas what you want is:

SELECT Id, Data, Role, Name FROM funcionaries WHERE 1=1 AND Name= ?

To do this you could modify your code like so:

q := `SELECT Id, Data, Role, Name
FROM funcionaries
WHERE True`
if len(where) != 0 {
q = q + " AND " + strings.Join(where, " AND ")
}
rows, err := db.Query(q, values...)

Syntax error: right syntax to use near ' ' when creating a MySql trigger

According to PHPStorm, you need to add one more END IF; before the final END;

Alternatively, line 17, replace ELSE IF with ELSEIF

You have an error in your SQL syntax on for the right syntax to use near 'join-date DATE,credit DOUBLE(15,0) zerofill,PRIMARY KEY(id) )' at line

As @GordonLinoff says hyphens (-) are not allowed by default in column names (in identifiers). Nevertheless, you can use it if you enclose the identifier in back ticks, as in:

create table clients_info (
id MEDIUMINT NOT NULL AUTO_INCREMENT,
name CHAR(30) NOT NULL,
`join-date` DATE,
credit DOUBLE(15,0) zerofill,
PRIMARY KEY(id)
);

Or better off, use an underscore (_) instead to avoid using back ticks everywhere, as in:

create table clients_info (
id MEDIUMINT NOT NULL AUTO_INCREMENT,
name CHAR(30) NOT NULL,
join_date DATE,
credit DOUBLE(15,0) zerofill,
PRIMARY KEY(id)
);

I personally prefer the latter.

Right syntax to use near '?' ORDER BY

You intent is OK. However, databases do not support passing table names as variables; keep in mind that the query planner needs to be able to prepare the statement (that is, generate its execution plan) by looking at the parameterized query only (without seeing the parameters). Parameters are meant to pass literal values to the query.

So you are left with performing the validation in your application first (against a fixed list of values, or by querying information_schema.tables), and then concatenating the table name in your query:

$stmt = $connection->prepare("SELECT * FROM `$name` ORDER BY `score` DESC");
$stmt->bind_param("s", $name);
$stmt->execute();

Error Code: 1064. You have an error in your SQL syntax; near '' at line 2

I can eyeball your query and I see that you forgot a closing parenthesis.

SET @tablaCiutat = CONCAT ("SELECT ... 
where id_country=(
SELECT id_country FROM world_temp_stats.country
where Name='",vPais,"' and id_city=",vID," group by year(dt)
");

I think you got mixed up because year(dt) ends in a right-paren, but you need one more to close the subquery. Something like the following:

SET @tablaCiutat = CONCAT ("SELECT ... 
where id_country=(
SELECT id_country FROM world_temp_stats.country
where Name='",vPais,"' and id_city=",vID," group by year(dt)
)
");

You should also use query parameters for dynamic values in your prepared query, instead of string-concatenation.

But if it were me, I would change so many things about this code. Why use INTO OUTFILE, and why use a stored procedure at all? In my experience, MySQL stored procedures are more difficult than writing the code in virtually any client programming language. I hardly ever use MySQL stored procedures.

Mysql- syntax to use near '' at line 1

  1. You forgot the closing ) in your statement

    INSERT INTO persons (FirstName,LastName)
    VALUES('$_POST[firstname]','$_POST[lastname]')

    and

  2. You need to escape your user input

    • To avoid syntax errors in your query
    • and SQL injections

    Use Prepared Statements for that



Related Topics



Leave a reply



Submit