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
-
70
votes5
answers17559
viewsMysqli vs PDO - which is the most recommended one to use?
With the mysql_* entering the state deprecated, the PHP documentation recommends using PDO and Mysqli. What do you recommend for use? PDO seems to be best suited for working with object oriented…
-
43
votes1
answer2932
viewsIs using PDO the safest way to connect to a PHP BD?
I’m a beginner in PHP and would like to know if PDO(PHP Data Objects) is the safest way to connect to a database? I also need an example of how to make this connection and enter/select data.
-
25
votes3
answers22400
viewsWhat is the difference between bindParam and bindValue?
What’s the difference between Pdostatement::bindParam() and Pdostatement::bindValue()?…
-
15
votes1
answer2041
viewsSQL LIMIT parameterized in PHP with PDO
A few days ago, I stopped using the functions mysql_*(already obsolete), and I switched to PDO. I have a function that does query database, but I’m having some problems using the LIMIT with Prepared…
-
13
votes1
answer7485
viewsLaravel 5 and Sql Server
I need a help, I made several attempts to connect Laravel with SQL Server and all without success. However, I managed to make it work with pure php, using sqlsrv_connect and Code Igniter. Windows 10…
-
13
votes3
answers2365
viewsHow to verify if connected in the database?
how do I check my code PHP + PDO successfully connected to the database Mysql? With code like this it works: <?php /* Connect to a MySQL database using driver invocation */ $dsn =…
-
12
votes2
answers613
viewsDynamically delete multiple lines with PDO?
Let’s say I have a user table (id | nome) and that where they are listed (client-side) i can select several of them and delete them at the same time. How could I do this in a Mysql database using…
-
10
votes3
answers1808
viewsSecurity when creating a PDO query function
I am now migrating to PDO because of security, but I don’t know if I am using PDO correctly. I am creating these functions to make faster the use of PDO, but I do not know if this form is safe. It’s…
-
10
votes2
answers1078
viewsIncrease timeout of dblib connection with PDO
On a connection to an external server (MS SQL SERVER), from another system with which I integrate some data, it is extremely slow, and with that the connection with the database gives error. How to…
-
8
votes1
answer1256
viewsInvalid parameter error when doing PDO perform action
I’m trying to learn how to use PDO, so I’ve already worked HARD looking for everything to understand it. So I’m at a point that has left me quite confused. I got the following code, he’s the:…
-
8
votes3
answers16157
viewsAutomatically load content when you reach the bottom of the page
I want to make an automatic page like Facebook, which when it reaches the bottom of the page automatically loads another page with more posts. I’ve already researched the subject and I haven’t found…
-
8
votes1
answer1660
viewsPooling Connection management by PDO
We often see in the applications multithreaded using connection to a database, the use of a Connection Polling, where you keep an open "pool" of connections, thus increasing performance so that you…
-
8
votes3
answers1513
viewsIs there an application security flaw when using AJAX?
I am a programmer HTML/CSS/PHP a few years and by incredible and more impossible it seems, I’m just entering the world of Javascript with jQuery and AJAX now. My question is whether the security…
-
8
votes2
answers13586
viewsHow to install the PDO_PGSQL driver in Ubuntu?
I have already installed PHP 7, Apache 2 and Postgresql 9.5. I’ve already enabled the extension on php.ini but it doesn’t work. In Windows just enable this extension on php.ini that already works…
-
7
votes3
answers7057
viewsSystem of infinite categories and subcategories/children
I’m putting together a system of infinite categories and subcategories, simple to begin with. I found a script on the internet that meets the requirements, but its customization and adaptation to my…
-
7
votes2
answers5639
viewsRescuing the last insertion in the bank with lastInsertId PDO
I’m trying to rescue the last id in the bank with lastInsertId() of the PDO, but nothing appears. OBS: I’m using the Postgre. <?php try { $dbh = new…
-
7
votes1
answer1894
viewsDynamic bind with prepare()
I am doing a function using PDO, when I try to use the PREPARE method the function does not end successfully, replace PREPARE with QUERY changing some arguments and worked. But my question is this…
-
7
votes4
answers9913
viewsDifference between prepare() and query()?
I was making a select in a table. I went to see the result, returned false. Then I used the query and it worked. What’s the difference between the two? <?php $query =…
-
7
votes1
answer245
views -
6
votes2
answers824
viewsName of months in Portuguese and English
On the site where I work, I use the following query to display in English the dates that are stored in the database: $conn->exec("SET lc_time_names = 'pt_PT'"); However, I discovered that the…
-
6
votes3
answers502
viewsINSERT query does not work inside a loop
So guys, I’m not getting to solve this query problem within a foreach loop not run. At first I thought it was something wrong with Pdo->beginTransaction so I commented on that part and left only…
-
6
votes1
answer2821
viewsHow to limit the number of pages shown in a pagination?
With this question that already has solution, I got as a result a paginação com PDO but I have one more problem that will possibly be the subject of a reward next week. As you can see in the image…
-
6
votes3
answers641
viewsHow to connect to Mysql only once, without having to instantiate every time?
How do I connect to Mysql only once, without writing it again in every function? Currently I do so: class Site { var $driver; var $host; var $dbname; var $user; var $pass; public function…
-
6
votes2
answers555
viewsDifference between fetch and setFetchDP methods
I understood the difference between fetch and fetchAll, but now, what is the difference between those and setFetchMode? Looks like it’s the same thing... (at least when it comes to riding). I can do…
-
6
votes1
answer1423
viewsdisplay products by listed category of the database with PHP PDO
I’m having difficulty to list products by category, I created only one page and wanted to be dynamic the display of products according to the category listed in the database, but not certain and in…
-
5
votes2
answers8457
viewsClose PDO connection
I have worked with other languages before working with PHP and in some the framework when you opened a connection with the database was good to finish it, in PDO so I realized there is a function in…
-
5
votes2
answers1344
viewsQuote problem when doing INSERT SQL
I’m doing a CRUD with PDO, but the method query prepare() only works with "crooked quotes" Ex (that’s how it works): "INSERT INTO `_user` (`firstname`) VALUES ('blabla')" It doesn’t work anymore:…
-
5
votes2
answers9506
viewsHow to connect PHP to Sqlserver via PDO
I’m using the following code: try { $con = new PDO("sqlsrv:Server=172.20.21.193,9090;Database=sgt","deb","123123"); $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch…
-
5
votes1
answer1187
viewsError in PDO query
I am creating a registration page where I have several tabs, as the structure below: <div> Aba 1 </div> <div> Aba 2 </div> <div> Aba 3 </div> <div> Aba 4…
-
5
votes2
answers1325
viewsBrowse query records with PHP PDO
I’ve always worked with ASP connections using ADODB and navigating the regressions that the query returned to me was not a problem because there were: <% rs.movenext //anda para proxima linha do…
-
5
votes1
answer761
viewsUse PDO Prepared statements in function
I’ve been reading about prevention sql injections and saw to use Prepared statements can help with that. I have the following function in a crud class I developed: public function inserir($tabela,…
-
5
votes2
answers14345
viewsSQLSTATE[HY093]: Invalid Parameter number Insert problem
I need to enter through a form the following data: TITLE DESCRIPTION PRICE HTML: <?php session_start(); session_destroy(); ?> <html> <head> <meta charset="UTF-8">…
-
5
votes1
answer124
viewsIs it a good practice to have the same name with the column name of the bank?
Let’s say I have one input text de name="txtnome", it is a good practice to have a column of the same name as this input on my table? Being that I’m using PDO for CRUD $st…
-
5
votes2
answers1093
viewsDelete data from cascading table
I have some relationships on my tables and I’m willing to delete inversely. on my system the user will have the option to delete a category, here comes my question as I will do this because it…
-
5
votes1
answer649
viewsHow to use LIKE in bindValue?
How to use the operator %, to the bindValue(), in query down below: $sql = 'SELECT * FROM nfe WHERE (cliente LIKE :cliente OR :cliente_ IS NULL)';…
-
5
votes2
answers491
viewsI cannot create php class and use PDO connection
I’m creating a class that fetches data from the database for display. For example, one of the functions of the class is to take the date, of a given, in the database and display on the screen. The…
-
5
votes2
answers1792
viewsJson output with json_encode()
json_encode() - Returns the JSON representation of a value If I do: $foo = array('a', 'b', 'c', 'd', 'e'); echo json_encode($foo); I’ll get: ["a","b","c","d","e"] So far so good, I’m taking an array…
-
5
votes2
answers324
viewsSearch with Mysql PDO in Array
I have that code: $whereBusca = "itaim-bibi"; $whereBusca = explode(',', $whereBusca); $sql = $pdo->prepare('SELECT id, nome, caminho FROM regiao WHERE caminho IN (:whereBusca)');…
-
5
votes1
answer482
viewsHow to select an option in select in a less laborious way?
I have a page called editarpublicacao.php who receives the id through GET. One of the two <select> for example contained on the page, is similar to that of companies: <select name="company"…
-
4
votes3
answers1343
viewsEmpty multiple tables in a single run
Via PDO, can do the TRUNCATE (English) of a table as follows: // Matriz de definições $dbcon_new = array( "host" => "localhost", "dbname" => "bubu", "username" => "super_dragon", "password"…
-
4
votes2
answers156
viewsWhy do I have to assign the value of the prepare method to a variable and only then instantiate execute? in Pdo
Ex: $stmt = $db->prepare("SELECT * FROM BD"); $stmt->execute(); Why doesn’t it work if I instantiate the execute method from the same instance? since the value has already been passed to the…
-
4
votes3
answers3897
views -
4
votes1
answer67
viewsHow to use the PDO class in this situation
I am using the PDO class to connect the database but in this particular situation I do not know how to use the PDO because in the mysql_fetch parameter I need to put a variable and so I searched…
-
4
votes1
answer315
viewsHow to properly step data type by PDO
In the php section below, what is the type of PDO::PARAM should I use ? $cnx = new PostgreSQL(); //Classe de conexão do banco $data = '2015-02-13'; $select = 'SELECT * FROM eventos WHERE "data" =…
-
4
votes1
answer3999
viewsHow to execute a pagination with PDO?
I am developing an application in PHP but I just started in PDO and I have no idea how to make a pagination using the same. I managed to put together a little query with example of the information…
-
4
votes1
answer7965
viewsIntegrity Constraint Violation: 1048 Column 'name' cannot be null
I am trying to create a system to upload PDF’s and always returns me the following error: Error Registering Record! - SQLSTATE[23000]: Integrity Constraint Violation: 1048 Column 'name' cannot be…
-
4
votes4
answers10030
viewsMysql error 1054 Unknown column
I’m making an SQL that counts how many names in the table start with any letter but an error is being returned: Column not found: 1054 Unknown column 'A' in 'Where clause' To the following SQL:…
-
4
votes4
answers1592
viewsHow to ask the PDO if the insertion was made or error?
How to ask the $Produtos if the insertion was made or if there was an error in the insertion attempt or die of mysql? if(isset($_POST['cadastra_produtos'])){ ///////////////////////////////////…
-
4
votes2
answers736
viewsPDO::rowCount() returning -1
I have this routine below, which used without problems with a Mysql database. However I had to migrate to a SQL Server 2008 database, which was simple. The only problem is, I don’t know why mine…
-
4
votes1
answer224
viewsKeep connection open in php webservice
I am building a simple webservice and PHP + JSON where I have 2 tables and I intend to perform CRUD operations. It is possible that the webservice is in the medium term consumed by many devices at…