pdo

PDO truncates my SQL string in Prepared Statement, tries to bind parameter number 0?

坚强是说给别人听的谎言 提交于 2019-12-24 01:37:14
问题 Okay, so I've spent a couple days trolling google and finding absolutely nothing on this. Basically I'm using a prepared statement that has a couple joins and matches based on several LIKEs, an IN, and a FREETEXT. I'm building the query dynamically to support the IN condition. I think some code will help public function searchForProjWithTags(Array $dSearchArgs, $dTags) { $bSplitTags = preg_split ("/[,]/", $dTags); $bCount = count($bSplitTags); $bQuestionMarks = "?" . str_repeat (",?", $bCount

Why does PDO::lastInsertId return 0?

▼魔方 西西 提交于 2019-12-24 01:17:54
问题 This is my code. // insert reward into wallet $sql = " INSERT INTO `wallet` (`uid`, `created_at`, `amount`, `type`, `payment_id`) VALUES (:uid, CURRENT_TIMESTAMP, :amount, 'payment', :payment_id); "; $sth = self::link()->prepare($sql); // primary key makes sure payment does not get double rewarded $sth->execute( array( ':uid' => $referer, ':amount' => $reward, ':payment_id' => $payment_data['payment_id'], ) ); var_dump(self::link()->errorInfo()); self::log("issuing subscription",self::LOG

update SQL table with multiple arrays using PDO

十年热恋 提交于 2019-12-24 01:07:56
问题 I would like to update a SQL table using PHP with PDO . However I keep getting the following error Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in C:\xampp\htdocs\core\functions\update_projects.php on line 31 I just can't make sense of where I'm going wrong. $j = 1; $chunk_count = count($update)/7; $backwards = array_reverse($update); $chunks = array_chunk($backwards, 7); var_dump($chunks[1]); try { for($i = 0; $i < $chunk_count; $i++

How to do a second PDO mysql query in a while loop from another query?

一笑奈何 提交于 2019-12-24 00:59:28
问题 So a snag I am hitting in using PDO MySQL is that if i run a query like so: $db->pquery("SELECT `category_id`, `category_name` FROM `database_categorys` ORDER BY `category_name` ASC"); while ($category = $db->fetch()) { } Inside the while loop i cannot do another query or it will cancel out the previous query, is there a way to get around that? This is my pquery btw: // A plain query public function pquery($sql) { $this->STH = $this->database->prepare($sql); $this->counter++; return $this-

PHP PDO Add filter to all queries

萝らか妹 提交于 2019-12-24 00:47:48
问题 Is there a way, using JUST PHP PDO (No ORMs) to globally filter all fetch/insert/update/delete operations. One example is a tenant field (in a multitenant db). I would like to globally add this type of filter to all operations: tenant = companyA Once again. NO ORMs, I already know how to do it with SQL Alquemy, Laravel's eloquent and Doctrine. I now want to know if it's possible just with PDO. 回答1: Create a class extending PDO like class DB extends PDO {... Normally i override the __construct

String encoding problem on PdoStatement->bindParam()?

自作多情 提交于 2019-12-24 00:17:43
问题 I'm trying to perform a simple SELECT statement from a string taken from a $_REQUEST var but it seem my PDO statement doesn't like the string format, why? My $_REQUEST var contains a string like Hello+World , so I need to replace + with whitespaces to do my SELECT statement correctly. // the data returned is Hello+World $phrase = str_replace ("+", " ", $_REQUEST["my_data"]); $phrase_select = $connection->prepare ("SELECT data_field FROM my_table WHERE phrase = ':phrase'"); $phrase_select-

PHP & PDO: One Connection vs More-than-one Connections

有些话、适合烂在心里 提交于 2019-12-24 00:16:01
问题 In my PHP program I need to hit the database between 0 and 3 times on any given webpage request. I am using PDO to interact with MySQL. First I create a database connection using something like this: $dbh = new PDO("mysql:host=$hostname;dbname=animals", $username, $password); Then I do what I need to do and close the connection like this: $dbh = null; I open and close a connection 0-3 times right now, the same number of times I need to interact with MySQL. My question is, should I be re-using

How to call PDOStatement::nextRowset() in Cakephp 3

蓝咒 提交于 2019-12-23 23:35:30
问题 I have created a procedure in which i there are two select statements are running. $stmt = $this->_connection->execute("CALL myFunction(:user_id)", [ 'user_id' => $userId ]); But when i am trying to call the nextRowset() like this $stmt->nextRowset(); Its giving me error Call to undefined method Cake\Database\Log\LoggingStatement::nextRowset() So, My question is how can i call the nextRowset() in Cakephp 3 回答1: Given that all core statement classes do extend \Cake\Database\Statement

PHP MYSQL PDO -> Fatal Error 23000 eventhough a special procedure is in place

爱⌒轻易说出口 提交于 2019-12-23 21:49:26
问题 I have a table in my db. My table has several fields including an auto-incremented id field set as primary key, and one other field called 'reference' that I did set as unique. To populate that table, I have a php script that insert records in that table using pdo. Every time an insert has been made successfully (meaning the 'reference' did not exist in the table), I increment a variable called $newOnes. If the value 'reference' is already in the table, an exception with the code 23000 is

PHP oci8 won't install through pecl: “fatal error: oci8_dtrace_gen.h”

拜拜、爱过 提交于 2019-12-23 21:38:47
问题 I am trying to connect my fedora 25 webserver - php to Oracle db. To do this I need to pecl install oci8. However I get this error: /bin/sh /var/tmp/pear-build-roottqYEC6/oci8-2.1.4/libtool --mode=compile cc -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-roottqYEC6/oci8-2.1.4/include -I/var/tmp/pear-build-roottqYEC6/oci8-2.1.4/main -I/var/tmp/oci8 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext