PHP School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a PHP Expert!

Join 307,116 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,000 people online right now. Registration is fast and FREE... Join Now!




DB2/SQL Problems :/

 

DB2/SQL Problems :/

Sue816

6 Nov, 2009 - 07:51 AM
Post #1

D.I.C Head
**

Joined: 22 Apr, 2009
Posts: 61



Thanked: 2 times
My Contributions
I'm in a PHP class and I have no idea what I'm doing. I'm frustrated with the instructor because the homework he gives has nothing to do with the chapters in the book...anyway...

So we have this assignment that we have a schema (PHPnn) and a new table called EMPFF. We are supposed to sort it by department, count the number of records, total the salary column and average the total salary.

That would all be peachy if I could even get the table to show up, I just get "Query Failed".

This is my code -

CODE

</body>
</html>

<?php

$sql = "SELECT EMPNO, LASNAME, FIRSTNAME, TITLE, TITLE, HOMEPHONE, ADDR1, ADDR2, ZIP, DEPT, WORKPHONE, GENDER, BIRTHDATE, HIREDATE, SALARY";

// Standard DB connection to DB2...
$conn = "*LOCAL"; $name = "emppf";    $pwd = "";
$DB2link = db2_connect($conn, $name, $pwd);
if (!$DB2link)
    echo 'Connection failed: '.db2_stmt_error().' : '.db2_stmt_errormsg();

    
$sql = "SELECT * from phpnn";
    
$stmt = db2_exec($DB2link,$sql)
or die("Failed query:".db2_stmt_error().":".db2_stmt_errormsg());

// Setup table header...
echo '<h1> Employee Database</h1>';
echo '<TABLE BORDER="10" BORDERCOLOR="red"><TBODY BGCOLOR="00FF00">';
echo '<TR><TD><B>EmpNo</TD><TD><B>LastName</TD><TD><B>FirstName</TD>
        <TD><B>Title</TD><TD><B>HomePhone</TD></TR>';
// loop di loop through customer recs...
while($row=db2_fetch_array($stmt)){
list( $Empno, $LasName, $FirstName, $Title, $HomePhone)= $row;        
echo("<TR><TD> {$row[0]}</TD> <TD>$Empno</TD> <TD>$LasName</TD>
        <TD>$Firstname</TD><TD>$Title</TD></TR>");
}

echo '</table>';
db2_close($DB2link);
?>


It's not finished, I don't have all of the column names in there, but I have no idea how to get it to connect. I've tried a few different ways. Can anyone see anything obviously wrong?

User is offlineProfile CardPM
+Quote Post


touch

RE: DB2/SQL Problems :/

6 Nov, 2009 - 08:47 AM
Post #2

New D.I.C Head
*

Joined: 20 Oct, 2009
Posts: 14



Thanked: 2 times
My Contributions
I could be totally wrong here, but this line

CODE
$sql = "SELECT * from phpnn";


is selecting the PHPnn schema. do you want it to select data from the EMPFF table instead?


CODE
$sql = "SELECT * from EMPFF";


User is offlineProfile CardPM
+Quote Post

CTphpnwb

RE: DB2/SQL Problems :/

6 Nov, 2009 - 08:50 AM
Post #3

D.I.C Lover
Group Icon

Joined: 8 Aug, 2008
Posts: 2,101



Thanked: 155 times
Dream Kudos: 100
Expert In: PHP

My Contributions
Why do you have html closing tags before your php code?
User is offlineProfile CardPM
+Quote Post

Sue816

RE: DB2/SQL Problems :/

6 Nov, 2009 - 09:15 AM
Post #4

D.I.C Head
**

Joined: 22 Apr, 2009
Posts: 61



Thanked: 2 times
My Contributions
Touch, probably. I will change that and see if it helps, lol.

CTphpnwb, I had a css but when I copied and pasted here, the rest of it went missing.
User is offlineProfile CardPM
+Quote Post

CTphpnwb

RE: DB2/SQL Problems :/

6 Nov, 2009 - 09:23 AM
Post #5

D.I.C Lover
Group Icon

Joined: 8 Aug, 2008
Posts: 2,101



Thanked: 155 times
Dream Kudos: 100
Expert In: PHP

My Contributions
Throwing in html is a good way to add confusion. I suggest you write and debug the php before adding html and css whenever possible.
User is offlineProfile CardPM
+Quote Post

Dannyboy997

RE: DB2/SQL Problems :/

6 Nov, 2009 - 10:42 AM
Post #6

D.I.C Head
**

Joined: 17 Apr, 2009
Posts: 77



Thanked: 2 times
My Contributions
i'm not sure why you have two $sql variables in the first $sql the sql statement is wrong. i'm not sure if those are tables or colums it looks like colums:



CODE


$sql = "SELECT EMPNO, LASNAME, FIRSTNAME, TITLE, TITLE, HOMEPHONE, ADDR1, ADDR2, ZIP, DEPT, WORKPHONE, GENDER, BIRTHDATE, HIREDATE, SALARY";




should be:

CODE


$sql = "SELECT EMPNO, LASNAME, FIRSTNAME, TITLE, TITLE, HOMEPHONE, ADDR1, ADDR2, ZIP, DEPT, WORKPHONE, GENDER, BIRTHDATE, HIREDATE, SALARY FROM EMPNO";



what you are trying to do is grab the colums but didn`t specify the table and thats why you get an error.

Hope this helps!
User is offlineProfile CardPM
+Quote Post

Sue816

RE: DB2/SQL Problems :/

6 Nov, 2009 - 12:50 PM
Post #7

D.I.C Head
**

Joined: 22 Apr, 2009
Posts: 61



Thanked: 2 times
My Contributions
QUOTE(Dannyboy997 @ 6 Nov, 2009 - 10:42 AM) *

i'm not sure why you have two $sql variables in the first $sql the sql statement is wrong. i'm not sure if those are tables or colums it looks like colums:



CODE


$sql = "SELECT EMPNO, LASNAME, FIRSTNAME, TITLE, TITLE, HOMEPHONE, ADDR1, ADDR2, ZIP, DEPT, WORKPHONE, GENDER, BIRTHDATE, HIREDATE, SALARY";




should be:

CODE


$sql = "SELECT EMPNO, LASNAME, FIRSTNAME, TITLE, TITLE, HOMEPHONE, ADDR1, ADDR2, ZIP, DEPT, WORKPHONE, GENDER, BIRTHDATE, HIREDATE, SALARY FROM EMPNO";



what you are trying to do is grab the colums but didn`t specify the table and thats why you get an error.

Hope this helps!



Thank you so much! That makes a lot of sense!

User is offlineProfile CardPM
+Quote Post

Sue816

RE: DB2/SQL Problems :/

6 Nov, 2009 - 01:09 PM
Post #8

D.I.C Head
**

Joined: 22 Apr, 2009
Posts: 61



Thanked: 2 times
My Contributions
I fixed that, but I think I have the schema name in the wrong spot. Where is the schema name supposed to go? Is it in "name"?
User is offlineProfile CardPM
+Quote Post

CTphpnwb

RE: DB2/SQL Problems :/

6 Nov, 2009 - 01:21 PM
Post #9

D.I.C Lover
Group Icon

Joined: 8 Aug, 2008
Posts: 2,101



Thanked: 155 times
Dream Kudos: 100
Expert In: PHP

My Contributions
Try changing:
$conn = "*LOCAL";

to:
$conn = "localhost";

or
$conn = "127.0.0.1";
User is offlineProfile CardPM
+Quote Post

JackOfAllTrades

RE: DB2/SQL Problems :/

6 Nov, 2009 - 01:23 PM
Post #10

I exist to Google your problems.
Group Icon

Joined: 23 Aug, 2008
Posts: 5,321



Thanked: 454 times
Dream Kudos: 50
Expert In: Being annoyed with lazy people.

My Contributions
Fixed topic title to something more appropriate.

Help, Help, Help is not a good title. We know you're here for help...
User is online!Profile CardPM
+Quote Post

Sue816

RE: DB2/SQL Problems :/

6 Nov, 2009 - 01:25 PM
Post #11

D.I.C Head
**

Joined: 22 Apr, 2009
Posts: 61



Thanked: 2 times
My Contributions
QUOTE(CTphpnwb @ 6 Nov, 2009 - 01:21 PM) *

Try changing:
$conn = "*LOCAL";

to:
$conn = "localhost";

or
$conn = "127.0.0.1";


Oh! Thank you. That worked. I have it now, and I realized what the teacher meant by "in your schema"...

Thanks again!
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 01:24PM

Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month