pdo

PDO interaction shared among classes

空扰寡人 提交于 2020-01-02 09:37:09
问题 I have a class for each database table I have, for example events table's rows are stored in Event classes. For each class I write, there are several methods that are exactly the same just with different variables or column names. For example: Player class update() public function update() { $conn = new PDO( db_host, db_user, db_pw ); $sql = "UPDATE players SET name=:name, picture=:picture, position=:position, num=:num, team=:team, description=:description WHERE id = :id"; $st = $conn-

Uploading Image Location to DB and Image File to Directory using PDO?

一笑奈何 提交于 2020-01-02 08:04:10
问题 could I get some assistance with this example code please, trying to add an image to the file directory while storing the link location in the database, but using PDO instead of the old way. It is based on an example I found online which comes with a dbconnect.php, save.php, addstudent.php and some others not needed for this query. <form method="post" name="frmStudent" action="save.php"> <input type="hidden" name="pid" value="<?php echo $ppid; ?>"/> <table> <tr><td>First Name</td><td>:</td>

Return Select * from PHP PDO Stored Procedure In MS SQL

好久不见. 提交于 2020-01-02 07:07:24
问题 For future users: The bottom of this question contains the corrected working code. I know Select * is not the best, but in this example, I am trying to call a stored procedure from php and return the ENTIRE result set so I can loop through the array in my code. Here is my current stored procedure: USE [hanoncs_AskMe] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET NOCOUNT ON; GO CREATE PROCEDURE [hanoncs_hanoncs].[CommentsTemp] @QuestionID INT AS BEGIN BEGIN TRANSACTION IF Object_id('

Creating PDO Iterator

我怕爱的太早我们不能终老 提交于 2020-01-02 05:41:26
问题 I'm flowing this article to create Database Iterator. I've similar tables and records. But when I executing I'm getting blank page. I think issue on $data = new DbRowIterator($stmt); , It's not returning proper iterator to run accept method in FilterIterator class. I'm using laravel 回答1: This article is a hoax. It claims that offered technique would speed up database calls with PDO, but in fact it slows them down significantly. Premises on which it is grounded are also wrong. PDOStatement is

PDO Get Multiple Insert Ids

六眼飞鱼酱① 提交于 2020-01-02 04:06:28
问题 Running the following query using PDO (Actually, I use prepared statements but same problem) INSERT INTO MyTable(MyField) VALUES('Row1'), ('Row2') How can I get the Ids for the records relating to Row1 and Row2 ? $db->lastInsertId() literally returns the last single Id. Is it sufficient to take this last Id, subtract the # of records and assume that range covers all my records? can there be gaps/jumps. Is this query guaranteed to be atomic? 回答1: If you're using MyISAM tables then because of

PHP PDO error when using placeholders in the LIMIT clause of a MySQL query [duplicate]

折月煮酒 提交于 2020-01-02 02:35:13
问题 This question already has answers here : How can I pass an array of PDO parameters yet still specify their types? (3 answers) How to apply bindValue method in LIMIT clause? (9 answers) Closed 4 years ago . $sql = "SELECT sql_calc_found_rows * FROM members". " ORDER BY username LIMIT :startRow, :numRows"; try { $st = $conn->prepare($sql); $st->bindParam(":startRow", $startRow, PDO::PARAM_INT); $st->bindParam(":numRows", $numRows, PDO::PARAM_INT); $st->execute(); } catch (PDOException $e) { die

Disabling PDO::ATTR_EMULATE_PREPARES causing 'unknown' issue

為{幸葍}努か 提交于 2020-01-02 02:35:09
问题 Just a quick question regarding PDO's ATTR_EMULATE_PREPARES attribute- simply put, while left on default (true) everything works fine and dandy. Disable it however and, well, I don't even get a PHP error message, just a browser warning telling me that "the connection was reset". For reference here is a sample of the code I was using <?php include_once("config.php"); try { $dbh = new PDO ( "mysql:host=". DB_SERVER .";dbname=" . DB_NAME, DB_USER, DB_PASS, array ( PDO::ATTR_PERSISTENT => true,

PHP PDO error when using placeholders in the LIMIT clause of a MySQL query [duplicate]

回眸只為那壹抹淺笑 提交于 2020-01-02 02:35:07
问题 This question already has answers here : How can I pass an array of PDO parameters yet still specify their types? (3 answers) How to apply bindValue method in LIMIT clause? (9 answers) Closed 4 years ago . $sql = "SELECT sql_calc_found_rows * FROM members". " ORDER BY username LIMIT :startRow, :numRows"; try { $st = $conn->prepare($sql); $st->bindParam(":startRow", $startRow, PDO::PARAM_INT); $st->bindParam(":numRows", $numRows, PDO::PARAM_INT); $st->execute(); } catch (PDOException $e) { die

How to make a PDO class method for inserting/updating/deleting with an unknown number of parameters in the arg

好久不见. 提交于 2020-01-01 19:46:13
问题 Currently Im trying to create a PDO class where I will have a method to run a query like INSERT, UPDATE, or DELETE. For examaple this is my method for a SELECT public function getPreparedQuery($sql){ $stmt = $this->dbc->prepare($sql); $stmt->execute([5]); $arr = $stmt->fetchAll(PDO::FETCH_ASSOC); if(!$arr) exit('No rows'); $stmt = null; return $arr; } And i Simply call it like this: $stmt = $database->getPreparedQuery($sql2); var_export($stmt); And so far I know that a runQuery should work

CodeIgniter is inserting twice the same entry. In some cases

我是研究僧i 提交于 2020-01-01 19:21:39
问题 I am trying to figure out why Codeigniter is inserting 2 times the same row in my Database. I'm using PDO as interface for mySQL. I was debugging it and I am sure the function bellow is not being executed two times. It happens in a particular case, if the two foreache's don't run because the array is empty, but if one of them runs the error doesn't happen. ` public function save_all() //save all information with the launched flag FALSE { include(database_vars_url()); try { $this->add_new