Page 1 of 1

Is there anything wrong with this code or>>?

Posted: Tue Mar 27, 2007 5:35 pm
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]

Posted: Tue Mar 27, 2007 5:44 pm
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

Posted: Tue Mar 27, 2007 5:45 pm
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?

Posted: Tue Mar 27, 2007 7:40 pm
by nickvd
Also, where is $dsn set?

Code: Select all

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