Page 1 of 1

PHP MYSQL connect brings up a blank screen

Posted: Wed Feb 11, 2004 9:33 am
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.

never mind

Posted: Wed Feb 11, 2004 9:45 am
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");

Re: never mind

Posted: Wed Feb 11, 2004 10:15 am
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 :)