NooB :: Database connection PHP5 and mySQL5 for MAC.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
sharky
Forum Newbie
Posts: 17
Joined: Sun Jun 04, 2006 12:31 pm

NooB :: Database connection PHP5 and mySQL5 for MAC.

Post by sharky »

arborint | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I'm having a problem to connect from the database (I'm using a MAC machine). I dunno what's the difference between MAC and PC in terms of SQL configuration, etc. Anyway here's some info[color=blue] (in config.inc.php)[/color] ::

Code: Select all

$cfg['Servers'][$i]['host']               = '[color=red]localhost[/color]'; // MySQL hostname or IP address
$cfg['Servers'][$i]['port']                = ' ';          // MySQL port - leave blank for default port
$cfg['Servers'][$i]['auth_type']      = '[color=red]config[/color]';    // Authentication method (config, http or cookie based)?
$cfg['Servers'][$i]['user']               = '[color=red]root[/color]';      // MySQL user
$cfg['Servers'][$i]['password']        = '[color=red]password[/color]';          // MySQL password (only needed
database :: tester
table :: products

What I did ::

----------------config.php------------

Code: Select all

<?php
// This is an example of config.php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$dbname = 'tester';
?>

-------------------opendb.php---------

Code: Select all

<?php
// This is an example opendb.php
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
?>

-------------closedb.php-------------

Code: Select all

<?php
// an example of closedb.php
// it does nothing but closing
// a mysql database connection

mysql_close($conn);
?>

------------------tester.php-------------

Code: Select all

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
include 'config.php';
include 'opendb.php';

SELECT * FROM products;

include 'closedb.php';
?>
</body>
</html>

When I open my tester.php, it's blank. What else should I check, eg :: SQL configuration, or configure the SQL in terminal, etc. Thanks in advance.


arborint | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

First, please be kind and wrap your PHP code in either

Code: Select all

or [syntax="php] tags.

Next, add the following two lines to the top of your PHP script, clear your browser cache and run the file again. Then report back with the errors you get.

[syntax="php"]<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', true);
?>
[/syntax]
Post Reply