PHP MYSQL connect brings up a blank screen

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
User avatar
LegionPete
Forum Newbie
Posts: 7
Joined: Wed Dec 31, 2003 3:36 pm

PHP MYSQL connect brings up a blank screen

Post by LegionPete »

I am trying to access a mysql database using php. When it gets to the connect statement, it just simply stops. Now, when I try to connect using perl, I have no problems, and am able to add, delete, and edit everything in the database. I'm not really sure what is wrong with it.

<?php
require_once('c:/wampp2/php/pear/DB.php');
$dsn='mysql://root:@127.0.0.1/test';

#works till this point
$dbh=DB::connect($dsn);
if (DB::iserror($dbh)) { die($dbh->getMessage());}

?>

first off, I had to add c:/wampp2...etc for it to get it to begin to work. Any suggestions.
User avatar
LegionPete
Forum Newbie
Posts: 7
Joined: Wed Dec 31, 2003 3:36 pm

never mind

Post by LegionPete »

found some useful info from another forum...works fine.

/* Connecting, selecting database */
$link = mysql_connect("localhost", "username", "password")
or die("Could not connect : " . mysql_error());
echo "Connected successfully";
mysql_select_db("matrix_lists") or die("Could not select database");
User avatar
dimitris
Forum Contributor
Posts: 110
Joined: Wed Jan 14, 2004 3:47 am
Location: Athens, Greece

Re: never mind

Post by dimitris »

LegionPete wrote:found some useful info from another forum...works fine.

/* Connecting, selecting database */
$link = mysql_connect("localhost", "username", "password")
or die("Could not connect : " . mysql_error());
echo "Connected successfully";
mysql_select_db("matrix_lists") or die("Could not select database");
I guess you hadn't looked to enough tutorials!
The last script is very popular but you could also make a connect file such as connect.inc or connect.php and call it wherever you wanted to make a mysql_query:

Code: Select all

<?php
function connect_db() {
    $db_server   =  'localhost';
    $db_user     =  'user';
    $db_password =  'pass';
    $db_database =  'my_db';
    $dbi = mysql_connect($db_server, $db_user, $db_password) or die(mysql_error());
    mysql_select_db($db_database);
    return $dbi;
}
if (!isset($dbi))  $dbi = connect_db();
?>
you can call it just by using require_once("connect.inc");
or include("connect.inc");
Keep Going :)
Post Reply