I have following code:
<?php
$exists_photos = $wpdb->get_results("SELECT * FROM $dsp_galleries_photos galleries, $dsp_user_albums_table albums WHERE galleries.album_id=albums.album_id AND galleries.status_id=1 AND galleries.album_id IN ($ids1) ORDER BY RAND() LIMIT 6");
$i=0;
foreach ($exists_photos as $user_photos) {
$photo_id=$user_photos->gal_photo_id;
$album_id1=$user_photos->album_id;
$file_name=$user_photos->image_name;
$private=$user_photos->private_album;
$image_path="/wp-content/uploads/dsp_media/user_photos/user_".$member_id."/album_".$album_id1."/".$file_name;
if(($i%3)==0){
?>
It returns following error:
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 ')' at line 1 for query SELECT COUNT(*) FROM wp_dsp_galleries_photos WHERE status_id=1 AND album_id IN () made by require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), include('/themes/ArtSee/page.php'), the_content, apply_filters('the_content'), call_user_func_array, do_shortcode, preg_replace_callback, do_shortcode_tag, call_user_func, wp_include_file, include('/plugins/dsp/profile_header.php'), include('/plugins/dsp/member_dsp_header.php'), include('/plugins/dsp/headers/view_profile_header.php'), include('/plugins/dsp/view_profile_setup.php')
Suggestions will be appreciated. Thanks
You missed a VALUE INSIDE ():
SELECT COUNT(*) FROM wp_dsp_galleries_photos WHERE status_id=1 AND album_id IN ()
The statement: 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 ')' indicates the point of failure. I refers to the second ) in :
... album_id IN () ...
In any case your code does not show this part.
SELECT * FROM $dsp_galleries_photos galleries, $dsp_user_albums_table albums
should be
SELECT * FROM dsp_galleries_photos galleries, dsp_user_albums_table albums
with no $ before the table name - you also should consider if you really need to select * but that won't impact the syntax of the query
Related
I am using this code>>>
$recipe_counting = $wpdb->get_var(
"SELECT COUNT(*)
FROM '" . $wpdb->prefix . "recipe_ratings'
WHERE recipe_id ='" . $post_ID . "' AND user_ip='" . $user_IP . "'"
);
In browser developer tools "Network" tab, it's showing this error when I try to check my output.
<div id="error"><p class="wpdberror"><strong>WordPress database error:</strong> [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 ''pr4_recipe_ratings'
where recipe_id ='104' and user_ip='::1'' at line 2]<br /><code>SELECT COUNT(*)
from 'pr4_recipe_ratings'
where recipe_id ='104' and user_ip='::1'</code></p></div>{"status":2}
You might try to remove the ' that encloses your tablename since the DB engine couldunderstand that you make the SELECT against a string.
The mariadb documentation for the SELECT statement (https://mariadb.com/kb/en/select/) mentions to use the backstick caracter ` to quote tablenames, not single quote.
You can quote column names using backticks. If you are qualifying column >names with table names, quote each part separately as >`tbl_name`.`col_name`.
Your query becomes the following
SELECT COUNT(*) from pr4_recipe_ratings where recipe_id ='104' and user_ip='::1'
When trying to select from 'jREwardToysRUs.dbo.MailDetail_198' table from jREwardToysRUs DataBase, I am getting the following error:
Invalid object name 'jREwardToysRUs.dbo.MailDetail_198'
Like below :
select top 10 *
from jREwardToysRUs.dbo.MailDetail_198
but giving [], the error is gone.Like:
select top 10 *
from [jREwardToysRUs.dbo.MailDetail_198]
Please suggest. how to remove error while selecting only with table name?
I think you are looking for "use" keyword:
use [jREwardToysRUs]
go
select top 10 *
from [dbo].[MailDetail_198]
I get following error message when trying to insert an object in the database:
com.ibm.db2.jcc.am.SqlIntegrityConstraintViolationException:
DB2 SQL Error: SQLCODE=-407, SQLSTATE=23502, SQLERRMC=TBSPACEID=2,
TABLEID=19, COLNO=0, DRIVER=4.15.134
How can I retrieve the table/column name for which the error is thrown?
Apparently at the package level, DB2 only works with the IDs and not the names.
You can find them back using the following query:
SELECT C.TABSCHEMA, C.TABNAME, C.COLNAME
FROM SYSCAT.TABLES AS T,
SYSCAT.COLUMNS AS C
WHERE T.TBSPACEID = 2
AND T.TABLEID = 19
AND C.COLNO = 0
AND C.TABSCHEMA = T.TABSCHEMA
AND C.TABNAME = T.TABNAME
I am currently constructing prepared statements and I am wondering how to use it in the WHERE part for LIKE and %. So I basically just want to SELECT the name from the database which is like the one that has been posted.
Here is my code:
$order = "SELECT name, name_id FROM requests WHERE name LIKE %?%" ;
$statement = $pdo->prepare($order);
$statement->bindParam(1, $_POST['name']);
$statement->execute();
$data = $statement->fetch(PDO::FETCH_ASSOC);
And here is the wonderful error that says that I use the wrong syntax with %:
Fatal error: Uncaught exception 'PDOException' with message
'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 '%'kevin'%' at line 1' in
/var/www/xxx/html/partials/requestinsert.php:13 Stack trace: #0
/var/www/xxx/html/partials/requestinsert.php(13): PDOStatement->execute() #1
/var/www/xxx/html/partials/requestcontact.php(231):
include('/var/www/xxx...') #2 /var/www/xxx/html/xxx.php(124):
include('/var/www/xxx...') #3 {main} thrown in
/var/www/xxx/html/partials/requestinsert.php on line 13
You need to supply query parameter when you bind the parameters like below:
$order = "SELECT name, name_id FROM requests WHERE name LIKE ?" ;
$var = "%" . $_POST['name'] . "%";
$statement->bindParam(1, $var);
Using Symfony with Sql Server and from what I've read, it seems that the connection to the database is not stable.
As soon as I use the orderBy method I get an error :
Here's an example :
$qStores =
$this->getManager()
->createQueryBuilder()
->select('rpdv')
->from('MainBundle:PointDeVenteReference', 'rpdv')
->andWhere( 'rpdv.partenaireClient = :id_partner ' )
->setParameter( 'id_partner', $this->getUser()->getPartenaire()->getIdPartenaire() )
->orderBy( 'rpdv.idPointDeVenteReference' , 'DESC' )
->setFirstResult( 0 )
->setMaxResults( 30 );
$stores = new Paginator( $qStores, FALSE );
And the error :
An exception has been thrown during the rendering of a template ("An exception occurred while executing
'SELECT DISTINCT TOP 30 id_point_de_vente_reference0
FROM ( SELECT p0_.id_point_de_vente_reference AS id_point_de_vente_reference0,
p0_.reference AS reference1,
p0_.date_derniere_modification AS date_derniere_modification2,
p0_.blocage AS blocage3
FROM point_de_vente_reference p0_
WHERE p0_.id_partenaire_client = ?
ORDER BY p0_.id_point_de_vente_reference DESC ) dctrn_result
ORDER BY id_point_de_vente_reference0 DESC'
with params [2829]:SQLSTATE[42000]:
[Microsoft][SQL Server Native Client 11.0][SQL Server]
The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions,
unless TOP, OFFSET or FOR XML is also specified.") in MainBundle:Default:store/list.html.twig at line 79.
I tried to change the class SQLServerPlatform with corrections found on the net, without success.
Do you have any idea?
Thx !
Edit :
This bug appears to be related to the Paginator with the second parameter to true. Passing it to false, I have no error
The dctrn_result is a derived table. From the error message, you can not use an order by. I do not know symfony2, but the code going to the database engine is invalid.
Craftydba