NooB :: Database connection PHP5 and mySQL5 for MAC.
Posted: Thu Jun 08, 2006 9:53 am
arborint | Please use
database :: tester
table :: products
What I did ::
----------------config.php------------
-------------------opendb.php---------
-------------closedb.php-------------
------------------tester.php-------------
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]
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 neededtable :: 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]