pdo

Caching PDO prepared statements

旧街凉风 提交于 2020-01-05 08:56:54
问题 Is there any point in saving PDO prepared statements for reuse in a session? I'm building a site that uses MySQL fulltext queries, which I'm putting together in my PHP, like SELECT * FROM table WHERE MATCH (title) AGAINST ($search_string IN BOOLEAN MODE) AND MATCH (keywords) AGAINST ($keywords IN BOOLEAN MODE) ORDER BY $order_by $asc_desc It seems to take a lot longer to run this kind of query when I prepare and execute it with bound parameters, than when I just prepare and execute a query

Conditional grouping clause (sqlite)

冷暖自知 提交于 2020-01-05 08:52:15
问题 Inside a SELECT statement, is it possible to GROUP BY col_A if col_B = "some_value" , otherwise GROUP BY col_C ? Then have that field that was used for grouping inside the results? Like SELECT value_of_the_column_used_for_group FROM table WHERE ... GROUP BY (IF col_B = "some_value" : col_A : ELSE : col_C) LIMIT 0, 20; Basically I want to select children records that have distinct parents or parent records that have distinct IDs. But I want to select parent IDs, which can be the ID column or

Conditional grouping clause (sqlite)

巧了我就是萌 提交于 2020-01-05 08:52:14
问题 Inside a SELECT statement, is it possible to GROUP BY col_A if col_B = "some_value" , otherwise GROUP BY col_C ? Then have that field that was used for grouping inside the results? Like SELECT value_of_the_column_used_for_group FROM table WHERE ... GROUP BY (IF col_B = "some_value" : col_A : ELSE : col_C) LIMIT 0, 20; Basically I want to select children records that have distinct parents or parent records that have distinct IDs. But I want to select parent IDs, which can be the ID column or

PHP PDO prepared statement IN() array [duplicate]

霸气de小男生 提交于 2020-01-05 08:43:09
问题 This question already has answers here : PDO binding values for MySQL IN statement (8 answers) PHP - Using PDO with IN clause array (7 answers) Closed 5 years ago . From the PHP Manual : You cannot bind multiple values to a single named parameter in, for example, the IN() clause of an SQL statement. But can you use multiple values using question mark parameter markers? Or do you have to prepare() a new statement every time the number of values changes? SELECT * FROM `table` WHERE `column` IN(

Laravel 5: Artisan throw PDOException could not find driver

家住魔仙堡 提交于 2020-01-05 08:24:10
问题 I've found other question like this but none seems to solve my problem. In my case it occurs on any artisan command, even if I just type "php artisan" the output is [PDOException] could not find driver . I'm running Laravel 5 on Ubuntu 14.04 LTS, with a LEMP stack (PHP 5.6 fpm, Mysql, Nginx). In the config/database.php the default driver is set to mysql. I've checked the output of php --ini , it seems to load all configuration files: Configuration File (php.ini) Path: /etc/php5/cli Loaded

MySQL WHERE LIKE not working with multiple fields using php and pdo bind

流过昼夜 提交于 2020-01-05 08:16:31
问题 I'm having an issue here with my WHERE LIKE statement. Ideally, I want to be able to search for multiple terms (or just 1 or the other). Right now, for testing purposes, I have this separated in my test form where I choose what type of function I'm running. Purpose : Please ignore the update function for the moment (I'm sure it's a mess like the rest but I haven't finished up there yet). Still trying to finish the dFind() function. The purpose of this testing is so that I can build a data

MySQL WHERE LIKE not working with multiple fields using php and pdo bind

放肆的年华 提交于 2020-01-05 08:16:06
问题 I'm having an issue here with my WHERE LIKE statement. Ideally, I want to be able to search for multiple terms (or just 1 or the other). Right now, for testing purposes, I have this separated in my test form where I choose what type of function I'm running. Purpose : Please ignore the update function for the moment (I'm sure it's a mess like the rest but I haven't finished up there yet). Still trying to finish the dFind() function. The purpose of this testing is so that I can build a data

How can i remove the oldest entries in my SQL result?

ε祈祈猫儿з 提交于 2020-01-05 08:15:22
问题 I want to get only the last reports, for all items but only the most recent report for each item_id . Here is my current solution: SELECT distinct * FROM t.reports ORDER BY created DESC LIMIT 100 My table consists of the following columns: id | user | item_id | created '2', '1', '2643', '2017-06-13 16:28:34' '3', '1', '19333', '2017-06-13 19:26:56' '4', '1', '19333', '2017-06-13 19:29:24' '5', '1', '1319', '2017-06-13 19:29:56' '6', '1', '1319', '2017-06-13 19:30:16' '7', '1', '1319', '2017

Combine Results from Two PDO queries

倖福魔咒の 提交于 2020-01-05 07:44:28
问题 I have the following line: $products = $dbh->query("SELECT piP2Components.typeID, invTypes.typeName FROM piP2Components INNER JOIN invTypes ON piP2Components.typeID = invTypes.typeID ORDER BY invTypes.typeName ASC;"); I have another table, piP3Components and I would like to run the same query on it and have the results added to the $products variable. As the result is a PDOStatement object I can't simply array_push. How would I go about doing this? Alternatively, I'm fairly new to using JOIN

PDO::exec or PDO::execute?

拟墨画扇 提交于 2020-01-05 07:36:30
问题 I use PDO to connect to my database and I don't know which method is better than the other one for UPDATE, DELETE and INSERT, PDO::exec or PDO::excute. Which should I use? 回答1: Although both methods have a similar naming (exec,execute) they're meant to be used in different scenarios: exec is used to get the number of affected rows. /** * (PHP 5 >= 5.1.0, PECL pdo >= 0.1.0)<br/> * Execute an SQL statement and return the number of affected rows * @link http://php.net/manual/en/pdo.exec.php *