Is there anything wrong with this code or>>?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
morpia
Forum Newbie
Posts: 11
Joined: Tue Mar 27, 2007 2:12 pm

Is there anything wrong with this code or>>?

Post by morpia »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Is there anything wrong with this code or is my hosting not working right?

I got all of this right out of a book that I bought and it isn't working on my site.

Code: Select all

<?php
$phptype = 'mysql';
$dbHost = 'localhost';
$database = 'morpiaco_videos';
$username = 'morpiaco_videos';
$password = '********';

$db = DB::connect($dsn);
if (DB::isError($db)) {
  die($db->getMessage());
}

$sql = "SELECT title, date, code FROM videos ORDER BY title DESC LIMIT 20";

$result = $db->query($sql);
if (DB::isError($result))
  $errorMessage = $result->getMessage();
  die($errorMessage);
}

$i=0;
while ($row = $result->fetchRow()) {
  $returnArray[$i] = $row[0];
  ++$i;
}

$db->disconnect();
?>
I am getting all sorts of errors such as this one..

Fatal error: Undefined class name 'db' in /home/morpiaco/public_html/videos.php on line 8


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

I'm not 100% positive but it looks like you're trying to use a class named 'DB' which isn't included in the file.
You can do what you're trying to do using:

http://uk.php.net/manual/en/function.mysql-connect.php
http://uk.php.net/manual/en/function.my ... ect-db.php
http://uk.php.net/manual/en/function.my ... -array.php
http://uk.php.net/manual/en/function.mysql-query.php
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

The error is pretty clear... it doesn't look like there's a "DB" class anywhere. Does the book assume you have included a class named DB, or have Pear DB installed?
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Also, where is $dsn set?

Code: Select all

$db = DB::connect($dsn);
Post Reply