So, we use a script called "phpmydirectory", and at this point it's pretty outdated. It wasn't designed to work on PHP 7+ or MySQL 5.7+ but we're mostly making it work.
Part of the script, you can import new "listings (like articles on a blog)" from a .csv file. We recently updated our database server from Ubuntu 18.04 to 20.04 and MySQL also updated to 8 from 5.7 (we have some strict mode settings turned off for date_time format etc).
I am seeing this error when importing and I'm not sure why:
Fatal Error: Database (1064) 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 'ROW, #previous_parent_id := parent_id, parent_id, id FROM pmd_lo' at line 1 in
file /usr/www/dd/phpmyd/includes/class_database.php on line 202 (SQL: UPDATE pmd_locations a, (SELECT IF(#previous_parent_id =
parent_id, #row := #row +1, #row :=1) AS ROW, #previous_parent_id := parent_id, parent_id, id FROM pmd_locations JOIN (SELECT #row :=0,
#previous_parent_id :=0) i ORDER BY parent_id, left_) aa SET a.child_row_id = aa.row WHERE a.parent_id = aa.parent_id AND a.id = aa.id) in
/usr/www/dd/phpmyd/includes/class_database.php on line 207
Here is the trace:
File: /usr/www/dd/phpmyd/includes/class_tree_gateway.php
Line: 111
Class: Database
Relevant PHP/MYSQL code:
https://www.paste.org/112726
File: /usr/www/dd/phpmyd/includes/class_imports.php
Line: 666
Class: Tree_Gateway
Relevant PHP/MYSQL code:
https://www.paste.org/112731
File: /usr/www/dd/phpmyd/cp/admin_ajax.php
Line: 616
Class: Imports
Relevant PHP/MYSQL code:
https://www.paste.org/112732
I'm really not sure here. Apologies.
Based on the keyword and reserved words information since version 8.0.2, ROW is now a reserved word:
So simply add quotes (or backticks) around that alias should help, such as: 'ROW'. There, and anywhere else the same may be needed.
Related
I am getting below error at server but working fine at localhost. I am using laravel Adjacency list https://github.com/staudenmeir/laravel-adjacency-list:
SQLSTATE[42000]: Syntax error or access violation: 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 'recursive `laravel_cte` as ((select *, 1 as `depth`, cast(`id` as char(65535)) a' at line 1 (SQL: with recursive `laravel_cte` as ((select *, 1 as `depth`, cast(`id` as char(65535)) as `path` from `user_relations` where `user_relations`.`parent_id` = 10000 and `user_relations`.`parent_id` is not null) union all (select `user_relations`.*, `depth` + 1 as `depth`, concat(`path`, '.', `user_relations`.`id`) from `user_relations` inner join `laravel_cte` on `laravel_cte`.`id` = `user_relations`.`parent_id`)) select count(`id`) as aggregate from `laravel_cte` where `status` = 0)
Please help me to solve it, I am clueless as I am new to this type of complex mySQL/MariaDB development.
"CTE" (WITH RECURSIVE ...) is not available until MariaDB 10.2 or MySQL 8.0.
Being a complete noob at PHP, I've been trying to install phpBB3 with several mods. However, something has broken the site and I can't receive support from the official forums unless I know which mod is causing the problems. Here is the error message I'm receiving:
SQL ERROR [ mysqli ]
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 '*, pb.id AS pb_id, pb.holding AS pb_holding FROM (phpbb_users u CROSS JOIN phpbb' at line 1 [1064]
SQL
SELECT u.*, z.friend, z.foe, p.*, gu.personal_album_id, gu.user_images, .*, pb.id AS pb_id, pb.holding AS pb_holding FROM (phpbb_users u CROSS JOIN phpbb_posts p) LEFT JOIN phpbb_zebra z ON (z.user_id = 2 AND z.zebra_id = p.poster_id) LEFT JOIN phpbb_gallery_users gu ON (gu.user_id = p.poster_id) LEFT JOIN phpbb_points_bank pb ON (pb.user_id = p.poster_id) WHERE p.post_id = 3 AND u.user_id = p.poster_id
BACKTRACE
FILE: (not given by php)
LINE: (not given by php)
CALL: msg_handler()
FILE: [ROOT]/includes/db/dbal.php
LINE: 757
CALL: trigger_error()
FILE: [ROOT]/includes/db/mysqli.php
LINE: 189
CALL: dbal->sql_error()
FILE: [ROOT]/viewtopic.php
LINE: 1050
CALL: dbal_mysqli->sql_query()
I'm not sure what other info I should post here, but feel free to ask. Thank you in advance.
Try to find the file containing this in the ultimate points mod, and add a ,after it, to be like this
'SELECT' => 'u.*, z.friend, z.foe, p.*, pb.id AS pb_id, pb.holding AS pb_holding,
Source is this link, but it is in Polish.
I'm new to PHP so bear with me.
This is the code for entering into a bookings table on my site:
http://pastie.org/8190189
And this is the error I get when I enter data into a form on the front end of the site:
http://pastie.org/8190194
I've been working at it for hours but I can't get anywhere.
I thought the problem may be with the:
SELECT u_id FROM `joom_hl_puser_role` WHERE pid = '1'
The table puser_role just connects joomla users to hotels that they can manage on the site. (I want to enter the hotel manager's joomla user number to the table).
but I'm sure that the syntax is correct.
Thanks for your help.
The problem is your use of TIME();
TIME needs a parameter passed.
mysql> select TIME();
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 ')' at line 1
Change it to
TIME(NOW())
From the MySQL manual for TIME
TIME(expr)
Extracts the time part of the time or datetime expression expr and
returns it as a string.
This function is unsafe for statement-based replication. Beginning
with MySQL 5.5.1, a warning is logged if you use this function when
binlog_format is set to STATEMENT. (Bug #47995)
mysql> SELECT TIME('2003-12-31 01:02:03');
-> '01:02:03'
mysql> SELECT TIME('2003-12-31 01:02:03.000123');
-> '01:02:03.000123'
you are in inserting the TIME() and NOW() functions inside "double quotes". try try chaing it to look like this
$query = "INSERT INTO `#__chbookings_bookings` (`id` ,`company` ,`firstname`,`lastname`, ,`email` ,`reference_number` , `transactionid` ,`invoice_number` , `property` ,`payment_type` ,`people` ,`phonenumber` ,`checkin_date` ,`checkout_date`,`room_type` , `status` , `total_amount` ,`amount_paid` ,`pending_amount`, `date_booked`,`last_updated`, `comments`) VALUES (NULL , '".$user_id."','".$data['firstName']."', '".$data['lastName']."',
'".$data['email']."', ".TIME().",
'".$result["transaction_id"]."','".$invoice_number."',
(SELECT u_id FROM `#__hl_puser_role` WHERE pid = '".$data['property_id']."'),
0 ,'".$total_adult."', '".$data['phone']."',
'".$session->get('checkin_date')."', '".$session->get('checkout_date')."', 0, 0,
'".$final_amount."', '".$session->get('amount_payable')."',
'".$session->get('balance_amount')."',
".NOW().", ".NOW().", 'comments'";
I have been facing an issue after another wile trying to access data from MySql Server from SQL server.
Here is what I have done so far.
1) installed MySQL ODBC Driver 5.2w on my SQL Server
2) I created a link server from Microsoft SQL Server Managment S (MSQLSMS)
following the instructions on this site
http://sql-articles.com/blogs/creating-linked-server-to-mysql-from-sql-server/
Now in my MSQLSMS I opened a connection to a server called "SERV1" I executed the following query and it is working with no problem.
SELECT
p.team_name,
p.fullname,
SUM( ISNULL(i.CallDurationSeconds, 0) ) AS totalTime
FROM OPENQUERY(SERVPHP, 'SELECT
CAST(t.name AS CHAR) AS team_name,
CAST(TRIM(REPLACE(CONCAT(su.first_name, " ", su.middle_name , " ", su.last_name), " ", " ")) AS CHAR) AS fullname,
CAST(su.login_user AS CHAR) AS username,
CAST(p.account_id AS UNSIGNED) AS account_id
FROM call_managment_system.phone_calls AS p
INNER JOIN call_managment_system.users AS su ON p.owner_id = su.user_id
INNER JOIN call_managment_system.teams AS t ON su.team_id = t.team_id
WHERE p.status = 2 AND t.client_id = 1 AND p.last_attempt_on BETWEEN "2013-01-01 08:00:00" AND "2013-04-30 07:00:00"
GROUP BY t.team_id, p.owner_id') AS p
INNER
JOIN OPENQUERY(SERVPHP, 'SELECT
CAST(cn.contact_number AS CHAR) AS phone_number,
CAST(cn.account_id AS UNSIGNED) AS account_id
FROM call_managment_system.contact_numbers AS cn
WHERE cn.contact_link = "Account"
UNION
SELECT CAST(cn2.contact_number AS CHAR) AS phone_number,
CAST(cn2.account_id AS UNSIGNED) AS account_id
FROM call_managment_system.contact_personal AS cp
INNER JOIN call_managment_system.contact_numbers AS cn2 ON cn2.person_id = cp.person_id AND cn2.contact_link = "Account" ') AS cn ON cn.account_id = p.account_id
INNER
JOIN I3_IC.dbo.CallDetail AS i ON p.username = i.LocalUserId AND RIGHT(i.RemoteNumber, 10) = cn.phone_number
WHERE i.I3TimeStampGMT BETWEEN '2013-01-01 08:00:00' AND '2013-04-30 07:00:00'
GROUP BY p.team_name, p.fullname
Now Since I am using PHP to execute this query. I have done the following
1) using PDO api to connect to the SQL server "SERV1" where I executed this query before.
2) try to execute that same query listed above.
But this time I get error where I am not able to solve.
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: [Microsoft][SQL Server Native Client 10.0][SQL Server]Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "SERVPHP"
Note that "SERVPHP" is the server where my PHP application is running and my MySql Server is running.
"SERV1" if where my SQL server is running and where I installed the ODBC driver.
More,
When I run this query the same way from my PHP application it works
SELECT
LocalUserId AS loginName,
RemoteNumber AS PhoneNumber,
SUM(CallDurationSeconds) AS totalTalk
FROM CallDetail
WHERE LocalUserId = 'test' AND
I3TimeStampGMT BETWEEN '2013-01-01 08:00:00' AND '2013-04-30 07:00:00'
GROUP BY LocalUserId, RemoteNumber
Why is it now working?
What do I need to make this query execute from my PHP server?
Thanks
Using the suggestions in the comments above, I discovered it was a permission issue.
I had to go to the Linked Server Properties and clicked on the "Security" menu on the left.
Then I had to add a user and a password. I also selected "Be made using the login's current security context".
Few weeks ago my code was all fine, but recently I've been unable to load my test database on my web app (built using CakePhp).
This is the 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 ') LEFT JOIN blogs AS Blog ON
(Song.blog_id = Blog.id) WHERE 1 = 1' at line 1
[CORE/cake/libs/model/datasources/dbo_source.php, line 684]
SELECT COUNT(*) AS `count`
FROM `songs` AS `Song`
LEFT JOIN libraries AS `Library` ON (`Song`.`id` = `Library`.`song_id` AND `Library`.`user_id` =)
LEFT JOIN `blogs` AS `Blog` ON (`Song`.`blog_id` = `Blog`.`id`)
WHERE 1 = 1
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 ') WHERE 1 = 1 ORDER BY Song.postdate
desc LIMIT 100' at line 1
[CORE/cake/libs/model/datasources/dbo_source.php, line 684]
SELECT *, Blog.id
FROM `songs` AS `Song`
LEFT JOIN libraries AS `Library` ON (`Song`.`id` = `Library`.`song_id` AND `Library`.`user_id` =)
WHERE 1 = 1
ORDER BY `Song`.`postdate` DESC
LIMIT 100
You don't have a condition for the Library.userid column:
Library.user_id =)
You need to specify a value on the right side of the equals sign!
your error is here:
Library.user_id =)
maybe you want to change it to:
Library.user_id ='$user_id')
It appears that some value for user_id is not being passed into the query:
`Library`.`user_id` =)
//-----------------^^^^
Likely, there is some PHP variable missing here, or a PDO parameter is not being correctly bound.
SELECT COUNT(*) AS `count` FROM `songs` AS `Song`
left JOIN libraries AS `Library`
ON (`Song`.`id` = `Library`.`song_id` AND `Library`.`user_id` =) <-- HERE's something missing
LEFT JOIN `blogs` AS `Blog` ON (`Song`.`blog_id` = `Blog`.`id`) WHERE 1 = 1
SELECT *,
Blog.id FROM `songs` AS `Song` left JOIN libraries AS `Library`
ON (`Song`.`id` = `Library`.`song_id` AND `Library`.`user_id` =) <-- HERE's something missing
WHERE 1 = 1 ORDER BY `Song`.`postdate` desc LIMIT 100
Since this is a CakePHP question, my answer will approach from the paradigms of the framework. However, given your SQL output, you are either NOT using CakePHP or you are doing something that is definitely a no-no.
Please post the Find statement that you are using the build this SQL statement and your Library's hasMany relationship to Blog. Unless you are using the query method, I think you would get a PHP error before you could build this type of SQL statement using the CakePHP find conventions. If you are using the query method to find your data, then don't. This is a simple query that can be done with CakePHP find easily.
Your library model should like like:
public $hasMany => array('Blog');
And the find:
$this->Library->find(
'all',
array(
'conditions' => array(
'1' => 1 //Not sure why you have Where 1=1
)
'order' => "Library.name DESC",
'limit' => 100
)
);