Skip to main content

Posts

Showing posts with the label pdo

How to manipulate a rowset data from sql to php

I have asked a question about how to retrieve data from different tables in sql How to get data from 4 tables in 1 sql query? When I run the query for my sample data I get 3 rows, anyway being many-to-many relationship between courses and categories I will always get more rows for same course. My question is how do I handle this data in PHP? I get an array and what I want would be something like: Array ( [0] => stdClass Object ( [name] => course name [tutor] => tutor name [categories] => Array ( categories here ) ); Should I just fetch the data from the categories in a foreach loop after I fetch a course? That would mean bad performance for large amount of data.

Converting MySQL to PDO

I've been advised a couple of times on here to start changing my code to PDO and I've finally got round to doing it. My problem is that I'm having incredible difficulty with converting my existing login script. For the last few lines of the code below (after the line $result = $query->fetchAll(); ) I haven't been able to find any resources online that could help me re-write it: $username = $_POST['username']; $password = $_POST['password']; $db=getConnection(); $username = mysql_real_escape_string($username); $query = $db->prepare( "SELECT password, salt, 'employer' as user_type FROM JB_Employer WHERE Username = '$username' UNION SELECT password, salt, 'jobseeker' as user_type FROM JB_Jobseeker WHERE User_Name = '$username'"); $result = $query->fetchAll(); $qData = mysql_fetch_array($result, MYSQL_ASSOC); $hash = hash('sha256', $qData['salt'] . hash('sha256', $password) ); if (

PDO_OCI: could not find driver

Today my problem is connected with PDO, OCI8 and PDO_OCI. But from the beginning. I'm using Ubuntu 11.10 and PHP version: 5.3.8-1ubuntu3. I have installed Oracle 10g Express, configured it and it works fine. The next step I had to do was integration between Oracle and PDO. So I found this link: http://lacot.org/blog/2009/11/03/ubuntu-php5-oci8-and-pdo_oci-the-perfect-install.html and do it step by step (without instaling PDO, which was installed previously with pdo_mysql). When I tried to do it on Ubuntu 10.10 - it was working. Now, on 11.10 I get an error: 'Could not find driver' when I try to open my website application. I checked phpinfo() and in the row PDO there are: PDO support - enabled, PDO drivers - mysql. There is nothing about oci in this section, although few lines under it I have PDO Driver for OCI 8 and later - enabled. Hope somebody can help with this. Best regards, Mateo.