How to fetch row in PDO?

Here is my code: $qs_num = $this->dbh->query("SELECT COUNT(amount), COUNT(*) FROM qanda WHERE type = 0"); print_r($qs_num); die; And here is the result: //=> PDOStatement Object ( [queryString] => SELECT COUNT(amount), COUNT(*) FROM q...
more »

2017-05-20 19:05 (1) Answers

Select from variable php and pdo

I have this PDO query: $records = $conn->prepare('SELECT taak FROM :selectfrom WHERE user_id = :id'); $records->bindParam(':id', $_SESSION['user_id']); $records->bindParam(':selectfrom', $selectfrom); For some reason this is not working. ...
more »

2017-05-20 18:05 (0) Answers

PDO bindParam not replacing multiple instances

I'm building a search function for my site and would like to search in the title and content of the articles. The query would look like SELECT id FROM articles WHERE title LIKE '%<user input>%' OR content LIKE '%<user input>%'; Is there...
more »

2017-05-20 17:05 (2) Answers

Data Exchange Between Functions

Yandex Translate I wrote a code like the following. I want to exchange this data between functions on the two pages. In other words, on the page $row variable I want to be able to use on this page, How Can I do that? Google Translate I wrote a code ...
more »

2017-05-20 10:05 (0) Answers

NULL stores 0, not NULL in my database

several columns in my MySQL rows whose values should be NULL (as there is nothing to insert) are 0, not NULL. Columns are type INT. Why is that? I need those to be NULL. Thanks for your help! Is it because PHP treats NULL, false, 0, and the empty st...
more »

2017-05-19 20:05 (1) Answers

PHP PDO update does not work (blank page)

I want to update a record in my database using pdo. The connection should not be the problem because I already use it for GET and INSERT. try { // Create connection $conn = new PDO("mysql:host=$servername; dbname=$dbname", $username, $passw...
more »

2017-05-19 16:05 (0) Answers

PDO Group fetched results by same ID

please help me cause I am totally lost on this one. I am trying to fetch the results from a database that has the data inserted in a weird way. The IDs are not unique, thus I have multiple values with the same ID in the ID column. I am trying to gr...
more »

2017-05-19 14:05 (0) Answers

PHP/MySQL - Email validation not working

I know this has been asked a lot, and I've search and literally tried it all. I'm really close, but can't get it to work. I'm trying to check if the username or usermail is already in use and display the error accordingly. <?php if (isset($_PO...
more »

2017-05-19 12:05 (2) Answers

Laravel 4.2 Eloquent only returning 1MB data

I have a mediumtext field in my mySQL database and it only return 1MiB data (a string with length 1048576) with the later part of the string trimmed when I query the database. A common solution I found online is adding this option to database.php con...
more »

2017-05-19 12:05 (1) Answers

Retrieve array from postgres

Very basic question but couldn´t find a solution. In a table with some values I try to store in 1 column a array (int[]) and retrieve it. The storing and searching works fine but if I select it I get it as string in php. Table week col id (int) ...
more »

2017-05-19 11:05 (1) Answers

Adding arrays to a php variable

I am using PDO in order to select some values from my database. For each iteration of my $teachArray, I store the selected array into my $language_id variable. I then get rid of any empty array that I have inside my $language_id and assigning it to...
more »

2017-05-19 07:05 (1) Answers

Remove empty arrays from PHP variable

I am using PDO in order to select some values from my database. For each iteration of my $teachArray, I store the selected value into my $language_id variable. However, I am also storing some empty arrays which is not my intention. I would like to...
more »

2017-05-19 05:05 (1) Answers

difficult SQL query syntax [Solved]

Edit: Thanks for Djaevel, the problem is solved.. Hello guys here are my MySQL query which one getting data... $videofetch = $conn->prepare("select * from user_followers as uf join videos as v on uf.followed_id = v.publisher_id where uf.followe...
more »

2017-05-18 16:05 (1) Answers

PHP PDO Connect Mysql

I´m trying to connect to my mysql database using PDO and it doesn´t seem to work. Is it something with the following code that I´m using or is the problem elsewhere? <?php $pdo = new PDO(';dbname=mydbname;',...
more »

2017-05-18 12:05 (1) Answers

Singleton pattern doesn't work with multiple db's

I have two db and i want to return one of them from my Db class which is actually Singleton pattern. So i don't want to make new connections every time but to check if connection exists in array and then to return it. The problem is that only thing t...
more »

2017-05-18 11:05 (1) Answers

Token validation not working

Hello guys I'm working on a php library that provides to make easier the token authentication with various automations. The problem is that when I try to validate the token sometimes it works and sometimes not, the function start a pdo connection to...
more »

2017-05-18 11:05 (0) Answers

Create a query in mysql php7 with variables?

I'm trying to create a query but it doesn't work. Where am I wrong ? $date = new \Datetime(date('d-m-Y')); $date->add(DateInterval::createFromDateString('- 2 day')); $date = $date->format('Y-m-d'); $stmt = $pdo->prepare('SELECT
more »

2017-05-18 10:05 (3) Answers

Print out login user data to match login SESSION

I'm very new to PHP and Mysql I'm writing shopping website for my assignment, I have my login, registration, and database up and running, and now I'm at the stage that needs to do my User profile page that is required to pull data out from database,...
more »

2017-05-18 09:05 (1) Answers

MySQL / PHP ( Foreign key mistake? )

I got a problem ^^ My PHP-function doesn't want to save into my MySQL table, but it saves it to my selected folder. (Connection works (tested), Inserting stuff into another table works too from this position.) I think it has something to do with the...
more »

2017-05-18 04:05 (1) Answers

Use mysqli or PDO instead?

I just uploaded my very old scripts on my hosting account. When I login to my website, I found this note. I read about mysqli but still don't work on changing Anyone please help! $con = mysql_connect('localhost', 'user_log', '12345'); $db = mysql_s...
more »

2017-05-18 04:05 (1) Answers

Converting PHP object to array

I have a query that returns the following object. How can I convert this object into an array and access the data within _results? I access the data through this query $test = $this->_db->get('shipping', array('uid', '=', $user->data()-&g...
more »

2017-05-17 18:05 (1) Answers

DOB mysql insert

I try to insert data from dropdown (day month year) into my database but i encountered an error please help. DOB set as a date format in my database. PS. however, it does insert to my year month day fine without any issue. Thanks in advance and s...
more »

2017-05-17 15:05 (1) Answers


Inglês It is possible to return an instance of class in Doctrine2? PDO is very simple $query->setFetchMode(PDO::FETCH_CLASS, 'model\vo\envio_vo'); ...
more »

2017-05-17 15:05 (0) Answers