pdo

MySQL get Primary Key after Insert Statment

情到浓时终转凉″ 提交于 2019-12-25 01:36:05
问题 I need to use the following insert statement, and the primary key field is auto increment. I need to return the new primary key value after the insert. Preferably using one statement to do the insert and return primary key value. $query = $database->connection->prepare("INSERT INTO accounts (created, priviledge, password, token, idle) VALUE ('$created', '1', :password, '$token_encrypt', '$idle')"); $query->bindParam(":password", $password_hash); $query->execute(); 回答1: As soon as you're using

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number

妖精的绣舞 提交于 2019-12-25 01:06:51
问题 Im having an error with select statment using pdo, and Im not understanding the reason why this is happening. Do you see something wrong here? I'm having this error: Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in $readGallery->execute(); $delId = $_GET['delid']; $thumb = $_GET['thumb']; $folder = '../uploads/'; $readGallery = $pdo->prepare("SELECT * FROM gallery WHERE news_id = ?"); $readGallery->bindParam(':news_id', $delId);

How to add a POST request for all inputs in PDO PHP

会有一股神秘感。 提交于 2019-12-25 01:04:10
问题 I have the following PHP PDO Update script, instead of having the inputs all hardcoded I would like to get the values from POST. How can I modify the following script to update both name and link to POST input values? <?php // Connection data (server_address, database, name, poassword) $hostdb = 'localhost'; $namedb = 'tests'; $userdb = 'username'; $passdb = 'password'; try { // Connect and create the PDO object $conn = new PDO("mysql:host=$hostdb; dbname=$namedb", $userdb, $passdb); $conn-

PHP PDO + PostgreSQL Connection Error: Could not find Driver

你说的曾经没有我的故事 提交于 2019-12-25 00:43:02
问题 There are a few similar questions that I have read through and followed the advice but to no end, and only being fairly new to this, I figured now was a good time to stop 'trying' things in case I break anything any further. I'm receiving the following error when trying to connect to my database via PDO: Connection error: could not find driver 1. I've ensured that Apache is linked to my homebrew PHP. $ which php /usr/local/bin/php 2. Have uncommented the following in php.ini extension=php_pdo

In PHP + PDO fetch the details of the query last executed or fill the question marks in query with corresponding entries

孤街醉人 提交于 2019-12-25 00:26:20
问题 I need to get the complete query with the filled values after the query got successfully executed, ( basically I want the query string with the question marks in the query removed and get replaced with corresponding values ) so that I can use it for transaction logging. below are the lines of code that I am using $stmt1 = $dbh->prepare("INSERT INTO announcements(id,routeID,ServiceAdvisoryID,ServiceAdvisoryDetailsId) VALUES (?,?,?,?)"); $stmt1->execute(array($aid,$route,$anctype,

Exception Using PayPal-PHP-SDK [Http response code 400]

删除回忆录丶 提交于 2019-12-24 23:34:30
问题 I'm following a tutorial about how to use PayPal-PHP-SDK and i got stuck in somewhere with this error in the console: [Sun Mar 08 16:11:21.729977 2015] [:error] [pid 4484:tid 1760] [client ::1:4308] PHP Fatal error: Uncaught exception 'PayPal\\Exception\\PayPalConnectionException' with message 'Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment.' in C:\\UniServerZ\\www\\PayPal\\vendor\\paypal\\rest-api-sdk-php\\lib\\PayPal\\Core\\PayPalHttpConnection

Phalcon pdo excpetion model first

懵懂的女人 提交于 2019-12-24 23:00:05
问题 I have problem with phalcon framework namely with models methods... As you know models has included methods find() and findFirst() I have generated model with phalcon-dev tools and now I am trying to do Model::find on it but I am getting an exception but dont know why... There is some more informations (e.g stacktrace) : http://exception.mateuszmarzecki.pl/ 回答1: You can try change methods in model file public static function find($parameters = array()) { return self::find($parameters); } 回答2:

count rows in table with many different parameters

最后都变了- 提交于 2019-12-24 21:58:12
问题 I know that I can count how many rows have a certain string in the columns of my table like this... $timeOfClass="W-7PM-A"; $inclass101 = $db->prepare("SELECT count(*) FROM students WHERE timeOfClass =?"); $inclass101->execute(array($timeOfClass)); $inclass101rows = $inclass101->fetchColumn(0); $inClass101rows reflects the number of rows in my database with $timeOfClass as W-7PM-A . But how can I do this for multiple variables of the $timeOfClass string without writing multiple SQL statements

Run a second query inside a foreach loop?

末鹿安然 提交于 2019-12-24 20:05:18
问题 Need to run 2 queries inside a foreach but cant do it without errors. So, i have this for showing comments: $query = 'SELECT * FROM comments WHERE updatepostid = "' . $postID . '"'; try { $stmt = $db->prepare($query); $stmt->execute(); $countcomments = $stmt->rowCount(); } catch (PDOException $ex) { die("Failed to run query: " . $ex->getMessage()); } $rows = $stmt->fetchAll(); foreach ($rows as $row): $commentID = $row['commentID']; $usercommentID = $row['userID']; $commentusername = ucfirst(

How to change an update query from mysql to pdo?

若如初见. 提交于 2019-12-24 18:44:40
问题 I am using the bellow query to update but now I tried to change it to pdo and it failed to work Please any help will be appreciated function updateonlinesession(){ if(isset($_SESSION['username']['id'])){ $uid = $_SESSION['username']['id']; $page = $_SERVER['REQUEST_URI']; $ip = $_SERVER['REMOTE_ADDR']; $username = $_SESSION['logged']; mysql_query("UPDATE site_user SET dateupdated = now(),ip = '$ip' WHERE username = '".mysql_real_escape_string($_SESSION['username'])."'"); } } Here is what I