MySQL Forums
Forum List  »  PHP

Re: Please help!!! Can't connect PHP with MySQL
Posted by: sweetmax sweetmax
Date: October 28, 2005 12:12PM

try this simple code:

<?php
mysql_connect('localhost', 'mysql_user', 'mysql_pass')
or die('could not connect:' . mysql_error());
mysql_db_name ('DB_name');
mysql_select_db('DB_name')or die('could not select DB');

?>

or

//connect to a singl db

function qdbconn() {
$dbUser = "myuser";
$dbPass = "mypassword";
$dbName = "mydatabase";
$dbHost = "myhost";

if (!($link= mysql_connect($dbHost, $dbUser, $dbPass))) {

error_log(mysql_error(), 3, "temp/phplog.err");
}

if (!mysql_select_db($dbName, $link)) {

error_log(mysql_error(), 3, "/temp/phplog.err");
}
}

/*
if you like, you could extend this function by creating links (for example, $link1,
$link2) to multiple databases on the same server.This code also records a MySQL error message to the
PHP error log.
*/

Options: ReplyQuote


Subject
Written By
Posted
Re: Please help!!! Can't connect PHP with MySQL
October 28, 2005 12:12PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.