LIKE query not working, it just output blank.    $stmt = $dbo-&gt;prepare("SELECT * FROM hotels WHERE h_country=:c LIKE '%m%'"); $stmt-&gt;bindValue(":c", "malaysia", PDO::PARAM_STR); $stmt-&gt;execute();
5230
Here's my attempt at it:  $query = $database-&gt;prepare('SELECT * FROM table WHERE column LIKE "?%"');  $query-&gt;execute(array('value'));  while ($results = $query-&gt;fetch())  {     echo $results['column']; }
17495
I have the following code:  $countQuery = "SELECT ARTICLE_NO FROM ? WHERE upper(ARTICLE_NAME) LIKE '% ? %'"; if ($numRecords = $con-&gt;prepare($countQuery)) {     $numRecords-&gt;bind_param("ss", $table, $brand);     $numRecords-&gt;execute();     $data = $con-&gt;query($countQuery) or die(print_r($con-&gt;error));     $rowcount = mysql_num_rows($data);     $rows = getRowsByArticleSearch($query, $table, $max);     $last = ceil($rowcount/$page_rows); }   Which should work fine. However I receive the error that :  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 upper(ARTICLE_NAME) LIKE '%?%'' at line 1  If I put  SELECT ARTICLE_NO FROM AUCTIONS WHERE upper(ARTICLE_NAME) LIKE '% o %';   The query works fine. $table is defined above, and query is received from GET, and both are correct valid values. Why is this failing?  edit: changing to:  $countQuery = "SELECT ARTICLE_NO FROM AUCTIONS1 WHERE upper(ARTICLE_NAME) LIKE '% ? %'";  if ($numRecords = $con-&gt;prepare($countQuery)) {      $numRecords-&gt;bind_param("s", $query);   results in the error:   Warning: mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: Number of variables doesn't match number of parameters in prepared statement in C:\Program Files\EasyPHP 3.0\www\prog\get_records.php on line 38  Commands out of sync; you can't run this command now  where as   $countQuery = "SELECT ARTICLE_NO FROM AUCTIONS1 WHERE upper(ARTICLE_NAME) LIKE ?";  if ($numRecords = $con-&gt;prepare($countQuery)) {      $numRecords-&gt;bind_param("s", "%".$query."%");   results in  Fatal error: Cannot pass parameter 2 by reference in C:\Program Files\EasyPHP 3.0\www\prog\get_records.php on line 38  and lastly  $countQuery = "SELECT ARTICLE_NO FROM AUCTIONS1 WHERE upper(ARTICLE_NAME) LIKE ? ";  if ($numRecords = $con-&gt;prepare($countQuery)) {      $numRecords-&gt;bind_param("s", $query);   will give only:  Commands out of sync; you can't run this command now  Is it impossible to use a paramter for a LIKE statament?
53082
To illustrate, assume that I have two tables as follows:  VehicleID Name 1         Chuck 2         Larry  LocationID VehicleID City 1          1         New York 2          1         Seattle 3          1         Vancouver 4          2         Los Angeles 5          2         Houston   I want to write a query to return the following results:  VehicleID Name    Locations 1         Chuck   New York, Seattle, Vancouver 2         Larry   Los Angeles, Houston   I know that this can be done using server side cursors, ie:  DECLARE @VehicleID int DECLARE @VehicleName varchar(100) DECLARE @LocationCity varchar(100) DECLARE @Locations varchar(4000) DECLARE @Results TABLE (   VehicleID int   Name varchar(100)   Locations varchar(4000) )  DECLARE VehiclesCursor CURSOR FOR SELECT   [VehicleID] , [Name] FROM [Vehicles]  OPEN VehiclesCursor  FETCH NEXT FROM VehiclesCursor INTO   @VehicleID , @VehicleName WHILE @@FETCH_STATUS = 0 BEGIN    SET @Locations = ''    DECLARE LocationsCursor CURSOR FOR   SELECT     [City]   FROM [Locations]   WHERE [VehicleID] = @VehicleID    OPEN LocationsCursor    FETCH NEXT FROM LocationsCursor INTO     @LocationCity   WHILE @@FETCH_STATUS = 0   BEGIN     SET @Locations = @Locations + @LocationCity      FETCH NEXT FROM LocationsCursor INTO       @LocationCity   END   CLOSE LocationsCursor   DEALLOCATE LocationsCursor    INSERT INTO @Results (VehicleID, Name, Locations) SELECT @VehicleID, @Name, @Locations  END      CLOSE VehiclesCursor DEALLOCATE VehiclesCursor  SELECT * FROM @Results   However, as you can see, this requires a great deal of code.  What I would like is a generic function that would allow me to do something like this:  SELECT VehicleID      , Name      , JOIN(SELECT City FROM Locations WHERE VehicleID = Vehicles.VehicleID, ', ') AS Locations FROM Vehicles   Is this possible?  Or something similar?
45100
I have a simple mysql table which I use as a server booking system. A user can log in to a server, if he has a valid booking for that server. A sample data might look like this:  +----------+----------------+---------------------+---------------------+ | server   | user           | start               | end                 | +----------+----------------+---------------------+---------------------+ | server01 | Alice,Bob      | 2013-10-28 00:00:00 | 2013-12-31 00:00:00 | | server02 | Carlos         | 2013-10-28 00:00:00 | 2013-12-31 00:00:00 | | server03 | Dan,Erin,Frank | 2013-10-28 00:00:00 | 2013-12-31 00:00:00 | +----------+----------------+---------------------+---------------------+   To check whether user Carlos has a booking for server02, I use the following SQL query:  SELECT 0, id FROM booking WHERE user = 'Carlos' AND (( start &lt; now() and end &gt; now() ) AND server = 'server02') ;   But this query does not work if there are multiple (comma-separated) users. How can I check if Alice has booking for server01 ?
66399
I have the following code:  const string Sql =      @"select distinct [name]        from tblCustomers        left outer join tblCustomerInfo on tblCustomers.Id = tblCustomerInfo.CustomerId         where (tblCustomer.Name LIKE '%@SEARCH%' OR tblCustomerInfo.Info LIKE '%@SEARCH%');";  using (var command = new SqlCommand(Sql, Connection)) {            command.Parameters.AddWithValue("@SEARCH", searchString);     ... }   This does not work, I tried this as well:  const string Sql =      @"select distinct [name]       from tblCustomers       left outer join tblCustomerInfo on tblCustomers.Id = tblCustomerInfo.CustomerId        where (tblCustomer.Name LIKE @SEARCH OR tblCustomerInfo.Info LIKE @SEARCH );";  using (var command = new SqlCommand(Sql, Connection)) {            command.Parameters.AddWithValue("@SEARCH", "'%" + searchString + "%'");     ... }   but this does not work as well. What is going wrong? Any suggestions?
110550
For a new project that I'm doing in PHP I've created an SQLMethods class to connect to the database and perform queries. Tonight was the first night that I actually got to test it (I wrote it a week or so ago and forgot about it) and an unexpected error occured: When it was calling my ExecuteQuery() function, it wouldn't use the database I selected in the constructor.  The constructor:      public function SQLMethods() {         $SQLConnection = mysql_connect($SQLDBAddress, $SQLUserName, $SQLPassword);          if (!$SQLConnection) {             die('Could not connect: ' . mysql_error());         }          mysql_select_db($SQLDB, $SQLConnection);     }   The function in question:      public function ExecuteQuery($Query) {         mysql_query($Query, $SQLConnection) or die('Could not perform query: ' . mysql_error());     }   Does anyone see what the issue might be? Does the connection close after the constructor completes?
123269
Inspired by a StackOverflow question ().  Is there a DBMS that actually supports the = NULL syntax?
8231
Simple one really.  In SQL, if I want to search a text field for a couple of characters, I can do:  SELECT blah FROM blah WHERE blah LIKE '%text%'   The documentation for App Engine makes no mention of how to achieve this, but surely it's a common enough problem?
44862
I have a problem binding booleans using mysqli_stmt::bind_param in PHP5. The SQL query is the following: insert into `nvp_notes` (subject,messageid,receivedate,read) values (?,?,?,?)  Where 'read' is a tinyint, either 0 or 1, as I've had issues with bit using mysqli. So the types that I list in bind_param are: $stmt-&gt;bind_param('sdsd', ...);  I've also tried 'sdsb' and 'sdss' but nothing seems to work, and I always get the message:  Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement  When I remove the read field in the statement everything works fine. I've run out of ideas with this one. Surely bind_param works with booleans?
34791
This is the announcement post of the Stack Exchange Data Explorer. Its answers were meant to iron out the initial glitches 6 to 8 years ago.  If you have found a bug or need support  today with any of SEDEs features, please ask a new question and tag it with   What does it do? Allows you to run arbitrary SQL queries on the data dumps, and share those queries with your friends. Technical details It is hosted on the Stack Exchange infrastructure , the database is hosted on the same SQL Server version all other sites are hosted on. You can use most of the TSQL commands, even create temporary objects (but not User Defined Functions). The controls used are jQuery based, the grid is  . All query results are cached, so sharing a link to a query will not result in the server going in to a tailspin. The query edit control is a slightly modified  control, I also am considering bespin cause the inter iframe communication is nasty complicated. It gives up nice syntax highlighting for queries. Parameters There is support for parameterized queries, to get it to work name your params like ##this##. For example have a . Query name and description A query can have a name and description, to name it lead with a comment, to describe it continue commenting, for example: -- This is my query name  -- This is my description -- I can span multiple lines  SELECT 1  Anonymous users can initially name a query, but can not change the names of any existing queries. Tutorial There's a  which helps you getting started in writing your own SQL queries. Logging in You can use your openid provider to log in, at the moment once logged in we will track the list of queries you execute (giving you basic history support) Also if there are any params named UserId they will be populated automatically if your EmailHash matches the one on the site being queried. Magic columns If you alias an id column with as [Post Link] it will automatically create a link in the result set to the parent site. Similarly if you alias an id column with as [User Link] it will display a link to the user page. select top 10 * from Posts will show you how tags are done. (Magic columns for images is planned) example (most controversial posts:  ) So what are you waiting for, check it out at  Any feedback would be greatly appreciated. I hope to have the login section working fairly soon and allow voting on the best queries and commenting. Featured Queries At the moment, admins have permission to feature interesting queries on this page , I am looking for better ways to manage the huge query list that is building up.
104262
I was writing some Unit tests last week for a piece of code that generated some SQL statements.  I was trying to figure out a regex to match SELECT, INSERT and UPDATE syntax so I could verify that my methods were generating valid SQL, and after 3-4 hours of searching and messing around with various regex editors I gave up.  I managed to get partial matches but because a section in quotes can contain any characters it quickly expands to match the whole statement.  Any help would be appreciated, I'm not very good with regular expressions but I'd like to learn more about them.  By the way it's C# RegEx that I'm after.  Clarification  I don't want to need access to a database as this is part of a Unit test and I don't wan't to have to maintain a database to test my code. which may live longer than the project.
117512
I am trying to run a SQL code (I use MySQL). What I want to do is to set DATE_REACT a value when the first condition is satisfied, and a different value when the first condition is not satisfied. The problem is that the first condition is executed always, even when it shouldn't. What I am doing wrong?  UPDATE BILLS SET STATE = 2, DATE_REACT = CASE  WHEN (DATE_EM &lt;= CURTIME() &lt;= ADDTIME(DATE_EM, '00:02:00')) THEN ADDTIME(CURTIME(), '00:13:00') ELSE ADDTIME(DATE_REACT, '00:13:00') END WHERE STATE = 1;
108487
I have the code below (I've included what I believe are all relevant sections):  private String readCommand = "SELECT LEVEL FROM USERS WHERE VAL_1 = ? AND VAL_@ = ?;"; public bool read(string id) {     level = -1;     MySqlCommand m = new MySqlCommand(readCommand);     m.Parameters.Add(new MySqlParameter("", val1));     m.Parameters.Add(new MySqlParameter("", val2));     MySqlDataReader r = m.ExecuteReader();     if (r.HasRows)         level = Convert.ToInt32(r.GetValue(0).ToString());     r.Close();     return true; }   When I run this, I get an IndexOutOfBoundsException on adding the first parameter. What have I done wrong?
62599
Possible Duplicate:          I'm using the mysqli extension in PHP and I'm wondering, is there possibly any way to see a prepared query as it will be executed on the server, e.g. The query is something like this  select * from table1 where id = ? and name = ?   but I want to see the query after the values are filled in, like this:  select * from table1 where id = 20 and name = "John"
31406
I am planning to replace repeatedly executed Statement objects with PreparedStatement objects to improve performance. I am using arguments like the MySQL function now(), and string variables.   Most of the PreparedStatement queries I have seen contained constant values (like 10, and strings like "New York") as arguments used for the ? in the queries. How would I go about using functions like now(), and variables as arguments? Is it necessary to use the ?s in the queries instead of actual values? I am quite confounded.
63457
Is there a way to mix LIKE operator with IN ? Something Like  SELECT Id FROM Account WHERE Name LIKE IN:nameList   Where nameList is list of String? Is this is possible ? (I can make a dynamic query by doing OR with all the elements, but was looking for a more elegant way to do this)
13728
I have database "raj" with table "pagination"  In table pagination have "id", "actualtime" and "created" field  id - auto_increment name- varchar created- datetime   I want to display all rows which is created on todays date display upto yesterdays 06:00 pm.after that the content will be refreshed based on based on a DATETIME field called 'created' that holds the date and time of each record's creation.  this is my query to fetch rows but it is not working properly...plz help me......  $sql = "     SELECT name      FROM pagination where created &gt;= DATE_SUB(CURRENT_DATE(),INTERVAL 1 DAY)        ";