problem connecting php with mysql

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
phpcoder2003
Forum Newbie
Posts: 5
Joined: Fri Aug 29, 2003 12:03 pm

problem connecting php with mysql

Post by phpcoder2003 »

hi !

I am new to php, and I am trying to connect to mysql database. I have Apache server, php and mysql on my local machine.

When I installed apache server and php and tried running phpinfo() script it worked fine.

after installing mysql, when I ran phpinfo() again it doesnt show me mysql on that page.

Also when I try to connect to mysql database, it gives me an error on "mysql_connect("localhost","username","password")

PLEASE HELP !! :(

Thanks,
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

ok. are you LAMP or WAMP? (linux/apache/mysql/php or windowws/apache/mysql/php)

there maybe differences between the issues you can have on the two....


do you have a mysql user?

try

Code: Select all

<?php
include("/path/to/file/db.stuff.php"); // get your db stuff

$test=mysql_connect('localhost', $username, $password) or die('problem connecting');
?>
in the included file, have $username and $password defined to be the user you want.
phpcoder2003
Forum Newbie
Posts: 5
Joined: Fri Aug 29, 2003 12:03 pm

Post by phpcoder2003 »

Thanks for the reply,

well i am WAMP

yes i did create users as below

mysql> GRANT ALL PRIVILEGES ON *.* TO monty@localhost
-> IDENTIFIED BY 'monty' WITH GRANT OPTION;

mysql> GRANT ALL PRIVILEGES ON *.* TO monty@'%'
-> IDENTIFIED BY 'monty' WITH GRANT OPTION;

mysql> GRANT RELOAD,PROCESS ON *.* TO admin@localhost;
mysql> GRANT USAGE ON *.* TO dummy@localhost;

Thanks !!
phpcoder2003
Forum Newbie
Posts: 5
Joined: Fri Aug 29, 2003 12:03 pm

Post by phpcoder2003 »

And ya if u can please explain the include line u told to try in ur code

<?php
include("/path/to/file/db.stuff.php"); // get your db stuff

$test=mysql_connect('localhost', $username, $password) or die('problem connecting');
?>


Thanks very much
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

ok. the path was becasue i'm using linux, so assuming you have a "PHP includes" folder in your "My Documents" folder...

include('C:\My Documents\PHP includes\my db stuff.php');

now, this means it's likely out of your web tree (good safety measure)...

now, this means it's like that file is at the front of your file that yo put that in. as long as you're not in a function you can use everything in taht file. that is where you put sensitive variables that you need for the database, and use that line to be able access it in your file
phpcoder2003
Forum Newbie
Posts: 5
Joined: Fri Aug 29, 2003 12:03 pm

Post by phpcoder2003 »

got it working !!!

Thanks for your help :D

one more question I had, for connecting PHP-Oracle what server I need :
Apache Server or Red Hat ?? Dont know much abt this.

Thanks for your help once again
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

I would say RedHat, as Apache is an webserver (ie. software running on an os, like Redhat).
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

i'm with jam on this, butif you're thinking about a posix os for oracle (which is a sql based relational db) you might wanna look at solaris... solaris/oracle seems to be the most common combo for it
Post Reply