MySQL Errors - phpBB3 - php

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.

Related

How to Translate Codeigniter Pre Formatted Query Into an Original Mysql Query (e.g $this->db->select('table1.*,table2.*,table3.*'))

I have a website which is using a CodeIgniter framework and almost using CodeIgniter's preformatted query class in every request to process data from database built by my ex coworker.
One of the example is like this:
function tampilkan_data(){
$this->db->select('barang.*,barang_keluar.*,barang_masuk.*');
$this->db->from('barang');
$this->db->join('barang_keluar', 'barang.id_barang=barang_keluar.id_barang','left');
$this->db->join('barang_masuk', 'barang.id_barang=barang_masuk.id_barang','left');
$this->db->order_by('barang.id_barang','asc');
$this->db->order_by('barang.kode_barang','asc');
$this->db->where('barang.status','0');
return $query = $this->db->get()->result();
}
I want to change the result from that query, but in order to understand it first I have to translate it into an original MySQL query. Attempted to do this:
SELECT `barang`.*, `barang_keluar`.*, `barang_masuk`.*
FROM `barang` AS A
LEFT JOIN `barang_keluar` AS B ON A.id_barang = B.id_barang
LEFT JOIN `barang_masuk` AS C ON A.id_barang = C.id_barang
ORDER BY A.id_barang ASC, A.kode_barang ASC
WHERE A.status = 0
But I got this 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 A.status = 0 LIMIT 0, 25' at line 6
I tried to remove the WHERE A.status = 0 to see which is wrong from my code the I got this error
1051 - Unknown table 'barang'
I thought the problem is in the line SELECT barang.*, barang_keluar.*, barang_masuk.*, because I didn't really know how to write it in an MySQL original formatted.
I already searched for this topic and I even tried to write the query straight to the search bar but I didn't find the right approach according to my case.
Hope someone can help
You can simply print your query, Then you can see your query in original sql format.
function tampilkan_data(){
$this->db->select('barang.*,barang_keluar.*,barang_masuk.*');
$this->db->from('barang');
$this->db->join('barang_keluar', 'barang.id_barang=barang_keluar.id_barang','left');
$this->db->join('barang_masuk', 'barang.id_barang=barang_masuk.id_barang','left');
$this->db->order_by('barang.id_barang','asc');
$this->db->order_by('barang.kode_barang','asc');
$this->db->where('barang.status','0');
$query = $this->db->get()->result(); // notice that i have removed the return keyword
echo $this->db->last_query(); // This will print your query directly on the screen.
}
But the error which you are getting is -> You don't have a table named barang.
Make sure that the table exists.
Hope It Helps...
If you want to look at the query string generated by the CI Query builder then you can log this method $this->db->last_query() which will give the last SQL query as string executed by it.
Your query is almost ok. But you will have to change it on order by. Because u have used asc more than once, that is not supported by mysql as well. You need to modify your query like below
SELECT A.*, B.*, C.*
FROM barang AS A
LEFT JOIN barang_keluar AS B ON A.id_barang = B.id_barang
LEFT JOIN barang_masuk AS C ON A.id_barang = C.id_barang
WHERE A.status = 0 ORDER BY A.id_barang, A.kode_barang ASC
Now be confirm that you have table barang in your database and try again. If you face another sql problem just reply with your screenshot of code snippet here.

Laravel DB:select() requires all columns in the group by

I need to run a custom query and I have tried all these methods
$sql = "SELECT acd.*, DATE_FORMAT(acd.cdate, '%d/%m/%Y') cdate_disp,
GROUP_CONCAT(CONCAT_WS(', ', car.type, car.session, crd.name) SEPARATOR '<br />') rd_names,
acb.booking_status my_booking_status
FROM app_data acd
INNER JOIN crmaccounts ca ON ca.id = acd.client_crm_id
LEFT JOIN crmaccount_rdids car ON car.account_id = ca.id
LEFT JOIN crmrd_ids crd ON crd.id = car.rd_id
LEFT JOIN app_bookings acb ON acb.call_ref_id = acd.call_ref AND acb.user_id = 12391
WHERE 1=1
AND acd.client_crm_id NOT IN (select account_id from bstaff WHERE user_id=12391)
GROUP BY acd.id
ORDER BY acd.cdate, ctiming";
DB:select($sql);
throws
Illuminate \ Database \ QueryException (42000)
SQLSTATE[42000]: Syntax error or access violation: 1055 'mydatabase.acd.call_ref' isn't in GROUP BY (SQL: ....)
DB::select($sql);
DB::raw($sql);
DB::select(DB::raw($sql));
//even with pdo
$sth = DB::getPdo()->prepare($sql);
$sth->execute();
$data = $sth->fetchAll(\PDO::FETCH_OBJ);
PDOException (42000)
SQLSTATE[42000]: Syntax error or access violation: 1055 'mydatabase.acd.call_ref' isn't in GROUP BY
It seems like the only way to get working is to list all the table columns in the group by which is doable but not convenient.
I am able to run the same query directly in the phpmyadmin. So I am not sure why when I run it through Laravel it asks me add all columns.
I have MariaDB installed and both Laravel and PhpMyAdmin are connecting to the same instance. Larvel version is 5.8.5.
Please take a look at full query as I asked question here too but couldn't find any answer - https://laracasts.com/discuss/channels/eloquent/query-runs-ok-in-phpmyadmin-but-dbselect-throws-exception
You should try disabling the strict mode in config/database.php, in mysql connection section.
This is not a Laravel issue, but a logical limitation by MySQL. When you add columns to your results set that are not in the GROUP BY clause, different values could be possible for these columns in the result set.
When executing queries in strict mode (which is on by default), MySQL will not allow this because it could lead to unexpected results. If you turn off strict mode MySQL will use the first result it finds for these columns.
You can turn off strict mode in your Laravel config files in config/database.php. However, it is recommended to change your query instead because of the unpredictability.
A full list of checks in strict mode can be found in the MySQL documentation: https://dev.mysql.com/doc/refman/8.0/en/sql-mode.html#sql-mode-strict
I have installed Laravel 4.8 and also configured Auth. further more,I add two tables called as role and states and tried your pdo code - its perfectly works for me! Here, I put my code.
$sql = "SELECT *
FROM users u
INNER JOIN roles r ON r.id = u.role_id
LEFT JOIN states s ON s.id = u.state_id
WHERE 1=1
GROUP BY u.id
ORDER BY u.id ";
$sth = DB::getPdo()->prepare($sql);
$sth->execute();
$data = $sth->fetchAll(\PDO::FETCH_OBJ);
dd($data);
I am eager to know what is your db structure.

Single force index throwing error on joined table

I'm trying to use a left join to bridge two tables and force index an index that only exists on the joined table, but I get the following 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 'FORCE INDEX (l.sfdcId) WHERE l.sfdcId = '003A000001eR0HsIAK'
ORDER BY a.activity' at line 3
Here's an output of the query being run (works fine if I remove the FORCE INDEX):
SELECT a.activityDate,a.primaryAttributeValue,a.attributeDescription,l.firstName,l.lastName,l.title,l.email
FROM activities AS a LEFT JOIN
leads AS l
ON a.leadId = l.leadId FORCE INDEX (l.sfdcId)
WHERE l.sfdcId = '003A000001eR0HsIAK'
ORDER BY a.activityDate DESC
Any idea why this would fail?
The FORCE INDEX goes after the table definition:
SELECT a.activityDate,a.primaryAttributeValue,a.attributeDescription,
l.firstName,l.lastName,l.title,l .email
FROM activities a LEFT JOIN
leads l FORCE INDEX (sfdcId)
ON a.leadId = l.leadId
WHERE l.sfdcId = '003A000001eR0HsIAK'
ORDER BY a.activityDate DESC ;

Executing OPENQUERY to pull data from MySql Server and inner joing it to SQL table from php script using PDO?

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".

Invalid SQL Syntax error

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
)
);

Categories