Most voted "pdo" questions
The PHP Data Objects (PDO) extension defines an interface for accessing PHP databases. Each database driver that implements a PDO interface can expose database-specific features as normal extension functions.
Learn more…927 questions
Sort by count of
-
3
votes1
answer101
viewsPDO with BIT type
I was now doing an instruction with on Duplicate and I have some fields like BIT. My class DB does the typing using PDO::PARAM_STR, PDO::PARAM_BOOL, PDO::PARAM_INT... but the use of these constants…
-
3
votes1
answer1839
viewsHow to close a database connection using PDO?
I’m new to PHP development and my app uses a method to open a database connection in Mysql, I am wanting to update and display the records. I need to use some method to close the connection, like:…
-
3
votes2
answers1260
viewsHow to insert all array values and avoid $query->execute() with each foreach run?
How to insert all array values and avoid $query->execute() to each execution of the foreach? $_POST = json_decode(file_get_contents('php://input'), true); $sql = "INSERT INTO teste(nome, email)…
-
3
votes2
answers457
viewsHow to work with PHP authorization levels?
I’m putting together a school bulletin system to train my skills in php. And I’m struggling in one part. Here’s the thing: I have 3 types of users: teacher, admin and student. The teacher can put…
-
3
votes1
answer1810
viewsHow to confirm the PDO UPDATE
Do you have a PDO function that allows you to check if UPDATE successfully competed? Same as the method 'lestInsertId()' is used to verify if a new ID has been generated in an auto incremented table…
-
3
votes1
answer156
viewsBug in PDO? Table disappears after INSERT command, how to debug?
Introducing I’m creating a library with some "magic methods" on top of PDO, already I did it with Mysqli and worked beautifully. The intention is to use in a Framework I am building, finally no more…
-
3
votes2
answers939
viewsQuery returns empty using PHP with PDO and MS Sqlserver
I’m migrating a system made in ASP to PHP. However, I’m having trouble making a query using PDO: Search.php class Busca extends Conexao { private $termo; public function setTermo($termo) {…
-
3
votes2
answers329
viewsselect Pdo com oo
I have this class that manages the database : <?php abstract class database{ /*Método construtor do banco de dados*/ private function __construct(){} /*Evita que a classe seja clonada*/ private…
-
3
votes2
answers117
viewsDoubt in the security of PHP PDO
I would like to know the difference in safety level between the two code snippets below: // TRECHO 1 <?php $calories = 150; $colour = 'red'; $sth = $dbh->prepare('SELECT name, colour, calories…
-
3
votes1
answer10445
viewsHow to perform UPDATE with PDO in PHP?
So guys, I wanted to rescue the data to edit on update.php, but I’m a little lost here, it’s got to give? <div class="container"> <div class="table-responsive"> <table…
-
3
votes1
answer522
viewsHow to connect tables that are in different databases?
I wonder how I can connect two tables that are in different databases to find data that are similar in the two tables. For example, we can have the table To-do shopping list and table Shopping list,…
-
3
votes1
answer53
viewsSum all results of a table and separate by day/month
I have a table where I would like to add all the results and separate them by Day/Month. 01/Abril = 3 Resultados; 03/Abril = 5 Resultados; 02/Maio = 1 Resultado; The table I’m using. **ID --…
-
3
votes1
answer150
viewsPHP Error return function
I have the following class with the methods: <? class minhaClasse extends database { public function funcao ($iduser) { $date = array($iduser, '1'); $sql = "SELECT * FROM `tabela` WHERE 'iduser'…
-
3
votes1
answer20225
viewsArray to string Conversion in
I am trying to make an INSERT in a table but is returning the following error: Notice: Array to string Conversion in C: xampp htdocs Moclient 3.0 modules products funEnviarPedido.php on line 25 Code…
-
3
votes5
answers2538
viewsHow to use Try Catch on an Insert
How do I use a Try catch to return an error from an Insert that was not inserted into the database. For example $sql = $pdo->prepare("INSERT INTO usuarios (nome,email,senha,telefone) VALUES…
-
3
votes3
answers56
viewsUse prepare statement at a constant value?
$type = 'post'; $stmtPG = $conn->prepare("SELECT count(*) FROM myTable WHERE entry_type = :type"); $stmtPG->bindParam(':type', $type); $stmtPG->execute(); $total =…
-
3
votes2
answers86
viewsDoes PDO use DBMS syntax or do they all work?
When considering the use of PDO, one of the main usability is the scope of several databases. Example scenario Different ways to filter 5 records, which vary by database: SELECT TOP 5 campo FROM…
-
3
votes1
answer281
viewsDifficulty updating data with angular and php
Good afternoon I’m trying to update the database and I can’t. If I use mysqli, the following warning appears on the console:…
-
3
votes0
answers418
viewsFatal error: Cannot redeclare class Connected
I have a problem that is a mystery to me, in my lodging at locaweb a website that was running normally yesterday morning to afternoon started to accuse me of a connection error, I have not yet…
-
3
votes1
answer775
viewsHow to convert latin1_swedish_ci data to utf8_bin in php?
I got an SQL script that "mounts" 3 tables, one with country, one with states and one with Brazilian cities. The script makes the collection, of the names, in latin1_swedish_ci and I needed it to be…
-
3
votes1
answer530
viewsInfinite loop, object orientation
Well, I’ve been doing some research, I found several topics talking about it, but none of them were useful to me, so I decided to turn to Stack Overflow. I have a role to list all user tickets that…
-
3
votes2
answers83
viewsResult SQL has field and index
I have a PHP function to automate the queries I do: //arquivo funcao.php function executaSql($sql, $param=array()){ try { include "config.php"; $q = $conn->prepare($sql); $q->execute($param);…
-
3
votes1
answer2398
viewsRun PHP without updating the entire page
My code is this: <?php $buscarusuario=$pdo->prepare("SELECT * FROM top5 WHERE status = 'ativo' ORDER BY colocacao ASC"); $buscarusuario->execute(); // Exibir com Fetch_Obj…
-
3
votes1
answer270
viewsSQL does not return all results
I have 2 tables in Mysql, a call municipalities and another call municipios_ibge both have a column called municipality that guards the municipality of each city in Brazil. I have to do the…
-
3
votes2
answers72
viewsProblems with PHP PDO
Next, I have the following method in a class called UsuarioDAO. public function insertUser(PojoUser $user) { if ($stmt = Conn::con() != null) { $stmt = Conn::con()->prepare('INSERT INTO usuario…
-
3
votes2
answers5829
viewsError in connection with bank using PDO
Error message: Error: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: This host is not known. code $db_name = 'db_name'; $hostname = 'mysql.hostinger.com.br'; $username =…
-
3
votes2
answers7609
viewsSQLSTATE[23000]: Integrity Constraint Violation: 1062 Duplicate entry '0' for key 'PRIMARY'
When trying to perform an INSERT in my table with PDO, I get the following error: SQLSTATE[23000]: Integrity Constraint Violation: 1062 Duplicate entry '0' for key 'PRIMARY' I’ve researched enough…
-
3
votes1
answer653
viewsQuery is executed, but the data does not go to the database
Good afternoon, Guys, I’m studying the PDO and with the following difficulty, the query runs (or rather, does not return me any error), only when I go to the bank has nothing, what I do? pdo = new…
-
3
votes1
answer70
viewsWhen relating two tables, is the correct one on the SQL side, PHP or whatever?
I have this doubt of what is preferred to do when I need data from the two tables to get the result. I always did the comparison in PHP, but I learned the SQL relationship commands that could help.…
-
3
votes1
answer510
views -
3
votes1
answer150
viewsMysql query with PDO does not return data
I have the following problem. I have developed a PHP class for a site I am creating and in one of these functions I am having problems with PDO. In giving the command SELECT I use the rowCount()…
-
3
votes0
answers195
viewsPHP with PDO returning BLOB records with foreach
Good afternoon guys, I’m new here (first question), but Stack has already helped me in several situations. That’s the problem: I am developing an application and on a given page there is a user…
-
3
votes1
answer820
viewsPDO Insert multiple lines into a single Insert using bindParam
I have a default function that I use for all of my Inserts (when they only have 1 Insert at a time), which would be: insereRegistro($sql, $param=NULL) { $query = $conn->prepare($sql); //Converte…
-
3
votes1
answer1601
viewsPHP PDO error handling
In PHP, how to make the PDO not to issue FATAL error, so that it is possible to identify and treat the error occurred? Example: Table: tb_requests: id fk_products Qtd 1 5 5 2 7 2 3 2 13 Table:…
-
3
votes1
answer191
viewsWhich correct way to update
Friends this mistake (SQLSTATE[HY093]: Invalid parameter number: parameter was not defined), what is the correct way to apply the UPDATE according to the code below? Campos DB id_seguradora…
-
3
votes1
answer7439
viewsReturn a PDO query in an array
How do I perform a query with PDO and return the results in a array. Ex: I need to make a query that returns me 10 rows, each row has 3 columns <?php $equipe1 = $_POST['equipe1'];//Pega o Nome da…
-
3
votes1
answer448
viewsSimultaneous connection on straight seats PDO
I need to make an appointment using two different banks and simultaneously. One is mysql and another firebird. It is already working separately, I would like to make the connection without having to…
-
3
votes1
answer370
viewsSQL Server PDO error: There are no more Rows in the active result set. Since this result set is not scrollable, no more data may be retrieved
I’m trying to take records from one table and record in another of the same kind, but I’m having this error: There are no more Rows in the active result set. Since this result set is not scrollable,…
-
3
votes4
answers702
viewsColumn 'idusuario' in Where clause is ambiguous
I’m trying to make a select with inner join. Rotating the select in the phpmyadmin the ERROR that returns is this: Column 'idusuario' in Where clause is ambiguous <?php $idusuario =…
-
3
votes1
answer487
viewsValidate data with PDO
I am migrating my php code in which I was using sql query to PDO, but I am finding it difficult to validate data with this. NOTE:I already have a functional file that does the search in the…
-
3
votes2
answers944
viewsMenu, submenus Dynamic NAV Bootstrap with PHP PDO Mysql
Good night. I need to assemble a dynamic menu, of three tables, that need to be interconnected, but I’m lost. Follow a part of the organization chart below: At the moment, I have the following code:…
-
3
votes2
answers1622
viewsTry/Catch Pdoexception does not work when error occurs
I created the following method to execute my querys: public function setQuery($query) { try { $stmt = self::$conn->prepare($this->limpaQuery($query)); return $stmt->execute(); } catch…
-
3
votes1
answer629
viewsParam Bind with Array - PHP and Mysqli
I have the code: <?php $clientes = implode(', ', $clientes); $busca = $mysqli->prepare("SELECT nome FROM clientes WHERE id IN (?)"); $busca->bind_param("s", $clientes);…
-
3
votes1
answer292
viewsConnection to separate PDO databases - (multi-tenancy )
I have the following password for my application: I have a PHP + Mysql application, with PDO connection, I need the application to be shared with all registered companies, but each company will have…
-
3
votes2
answers258
viewsIs it possible to manipulate SESSION variables to perform SQL Injection?
I’m not an expert on cyber attacks and I have a little doubt about the safety of my projects. Basically one of the ways I prevent injections SQL is creating a function "treatString()", for example,…
-
3
votes1
answer179
viewsHow to insert PDO records into Mysql sequentially
I am sending six fields of a form to insert in my Mysql but only the first three are going correctly, I need to insert the first three and in sequence the other three, but I have this difficulty in…
-
2
votes1
answer66
viewsFluent is safe, right?
Someone who’s already used the Fluent, Can you tell me if he’s safe with SQL Injects? All right that it uses PDO, but suddenly it does not treat the data before it is sent to the database. And if…
-
2
votes2
answers264
viewsSingle database instance
I have a controller and need to access 2 or more tables from my database, ex: $userModel = loadModel('userModel'); $userModel->setTable('users'); $userModel->getAllUser(); $outroModel =…
-
2
votes1
answer101
viewsAm I connecting the bank with PDO the right way?
There are several ways to connect to the database, but I opted for PDO. I’m doing it the right way? date_default_timezone_set('America/Sao_Paulo'); $pdo = new…
-
2
votes1
answer100
viewsConnections and management
PHP - PDO, Connections and Connection Management The connection remains active throughout the lifetime of the PDO object. To close the connection, you need to destroy the object, ensuring that all…