I'm getting an error while trying to query a custom table using the wpdb class. Here is my code :
global $wpdb;
$dates_bloquees = $wpdb->query(
$wpdb->prepare( "SELECT datesbloquees FROM $wpdb->datesbloquees WHERE idproduit = '%d' ", $postid ) );
Error message :
WordPress database 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 'WHERE idproduit = '1'' at line 1]
Can someone tell me what I'm doing wrong?
Thank you for your help,
François
Related
I'm using Node.js and TypeORM with MySQL but the error shows MariaDB I don't know why. I'm trying to use array in User entity and this must be the error
ERROR:
QueryFailedError: ER_PARSE_ERROR: 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 '' at line 1
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
code: 'ER_PARSE_ERROR',
errno: 1064,
sqlMessage: "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 '' at line 1",
sqlState: '42000',
index: 0,
sql: 'ALTER TABLE `user` ADD `favorites` text NOT NULL DEFAULT '
},
code: 'ER_PARSE_ERROR',
errno: 1064,
sqlMessage: "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 '' at line 1",
sqlState: '42000',
index: 0,
sql: 'ALTER TABLE `user` ADD `favorites` text NOT NULL DEFAULT '
}
The columns causing the error:
#Column({ type: "simple-array", default: [] })
favorites: string[];
#Column({ type: "simple-array", default: [] })
cart: string[];
You can't have default value for column type text in mysql. Remove the default parameter in the column options and the query should work.
If you still want to have any default value set, you can write a native mysql trigger or use typeorm #AfterInsert hook to set the value of columns cart or favorites just after they're inserted in the database.
Simple table:
CREATE TABLE `LocalTest` (
`mainJson` json NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Attempt to insert json value:
insert into `LocalTest` (mainJson) values ('{ "key": "value" }')
As result error:
Error Code: 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 'Error Code: 3140. Invalid JSON text: "The document root must not be followed by ' at line 3
What wrong with this simplest script?
SELECT `template_id`, replace(template_code,"AT -","DE -") as
template_code, `template_text`, `template_styles`, `template_type`,
`template_subject`, `template_sender_name`, `template_sender_email`,
`added_at`, `modified_at`, `orig_template_code`, `orig_template_variables`
FROM `core_email_template` WHERE template_code like "%AT - %"
This query it works and returns me some data that I want to export it. But when I do that from phpmyadmin I received this error:
Error reading data: (#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 'FROM WHERE
(`core_email_template`.`template_id` = 27) OR (`core_email_template' at
line 1)
What should I have to do to make this work ? thx
I'm a complete nubie to Ruby but have managed to get this far following these instructions:
https://github.com/sharetribe/sharetribe
But a straight copy/paste of this code into terminal results in errors. Any ideas?
c = Community.create(:name => "your_chosen_name_here", :domain => "your_chosen_subdomain_here")
tt = c.transaction_types.create(:type => "Sell",
:price_field => 1,
:price_quantity_placeholder => nil);
tt_trans = TransactionTypeTranslation.create(:transaction_type_id => tt.id,
:locale => "en",
:name => "Sell",
:action_button_label => "Buy");
ca = c.categories.create;
ca_trans = CategoryTranslation.create(:category_id => ca.id,
:locale => "en",
:name => "Items");
CategoryTransactionType.create(:category_id => ca.id, :transaction_type_id => tt.id)
Errors are:
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 'c = Community.create(:name => "marketfarm", :domain => "marketfarm")
c = Communi' at line 1
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 'tt_trans = TransactionTypeTranslation.create(:transaction_type_id => tt.id,
:lo' at line 1
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 'ca = c.categories.create' at line 1
etc.
Thanks for trying out Sharetribe!
First of all, we have updated the installation instructions. New installation instructions do not require this step.
In you case I guess there's somekind of copy/paste error there. Maybe you could try first copy/paste the command to a text editor (i.e. Notepad) and remove the line breaks and make the commands single line. I have notice that sometimes console doesn't understand multiline pasted commands.
I guess you are using any other database like sqlite or postgresql than Mysql.
Sharetribe only supports with Mysql database.
Thanks
The following is the most basic and simplest code I ever wrote, what could be wrong with that code?
<?php
$con=mysqli_connect("localhost","root","myroot","mydb");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else
{
echo "Connecting to server Localhost succeeded ! ";
}
// Add column
$sql="ALTER TABLE june2013 ADD time_interval (DECIMAL(5,2))";
if (mysqli_query($con,$sql))
{
echo "Column added successfully";
}
else
{
echo "Error creating database: " . mysqli_error($con);
}
mysqli_close($con);
?>
I get an error message that says:
Connecting to server Localhost succeeded !!! Error creating database: 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 '(DECIMAL(5,2))' at line 1
Any idea why I'm getting this?
Could it just be that you are missing "COLUMN" from the statement?
$sql="ALTER TABLE june2013 ADD time_interval (DECIMAL(5,2))";
should be
$sql="ALTER TABLE june2013 ADD COLUMN time_interval DECIMAL(5,2)";