Page 1 of 1

PHP5/MySQL connection string

Posted: Fri Jul 25, 2008 12:41 pm
by okelly
hello all...

i'm getting the following error from the connection string below (PHP 5.2.6, Apache 2.2.9, MySQL5, Win Vista Home)

\n"); print(mysql_errno() . ": "); print(mysql_error() . "
\n"); commonErrors(); exit(); } ?>

dbname, user and pw all tested in MySqlAdmin and are valid

thanks very much
Conor

Code: Select all

 
<?
 
// This should remain localhost unless specifically connecting to a remote database.
$dbhost = "localhost";
 
// The database name should be the same as the hosting account username.
$dbname = "mydb";
 
// The database username should be the same as the hosting account username.
$dbuser = "root";
 
// The database password should be the same as the hosting account password.
$dbpass = "****";
 
 
 
 
// Establish the connection to database
if(!($dblink = mysql_connect("$dbhost", "$dbuser", "$dbpass")))
{
    // Unable to connect to database so print an error
    print("Unable to connect to the MySQL database server!\n");
    commonErrors();
    exit();
}
// Select the database to use
if(!(mysql_select_db("$dbname", "$dblink")))
{
    // Unable to select the database
    print("Unable to select the $dbname database!<br>\n");
    print(mysql_errno() . ": ");
    print(mysql_error() . "<br>\n");
    commonErrors();
    exit();
}
?>
 
 
 

Re: PHP5/MySQL connection string

Posted: Fri Jul 25, 2008 12:53 pm
by EverLearning
You need full php tags at the begging of the file

Code: Select all

<?
should be

Code: Select all

<?php
In PHP5 the open_short_tags php directive is off by default.

Re: PHP5/MySQL connection string

Posted: Sat Jul 26, 2008 6:06 am
by okelly
thnx Everlearning. did the trick..