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.
PHP MYSQL connect brings up a blank screen
Moderator: General Moderators
- LegionPete
- Forum Newbie
- Posts: 7
- Joined: Wed Dec 31, 2003 3:36 pm
- LegionPete
- Forum Newbie
- Posts: 7
- Joined: Wed Dec 31, 2003 3:36 pm
never mind
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");
/* 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
I guess you hadn't looked to enough tutorials!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");
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();
?>or include("connect.inc");
Keep Going