LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-13-2006, 11:06 PM   #1
shipon_97
Member
 
Registered: Oct 2005
Location: Bangladesh
Posts: 504

Rep: Reputation: 31
Lightbulb Php and Mysql


Dear Friends ,

I have completed my PHP configuration in my "Redhat Linux Enterprise Edition 4" using the following built in RPM's :

1)http/apache server
2)PHP v 3
3)PHP-Mysql v 3
4)Mysql
Now i make a "test.php" file in "/var/www/html" directory .And i am running that page without no problem . In this moment i have a question :

If i want to make a project using PHP and Mysql Then

Is mysql automatically connects with my PHP ? or I need to make change One of a file to connect with PHP & Mysql ?

PLz inform .....
 
Old 02-13-2006, 11:47 PM   #2
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
If you have the php-mysql RPM installed then you can go ahead an use all the mysql_ functions in PHP.
 
Old 02-14-2006, 02:56 AM   #3
onjoo
Member
 
Registered: Jan 2005
Location: Finland
Distribution: Suse 10, Suse-factory , RHEL4, SLES9, SLED10
Posts: 380

Rep: Reputation: 30
If you have that php-mysql package installed, MySql is available, but you will still need to connect to the database.
I would use atleast php version4 and Mysql version 4 or higher versions because all those needed functions are not surely present at earlier versions.

Here is example code to connect and use Mysql
We tell php what database to use and give information about database user.
Then we select information from table named "users".

PHP Code:
<?php

function makeConnection() {
        
 
$dbhost="localhost:/var/lib/mysql/mysql.sock";
 
$dbusername="DBUSER";
 
$dbpassword="DBPASSWORD";
 
$dbname="DBNAME";

        
$connect mysql_connect($dbhost$dbusername$dbpassword);
        
mysql_select_db($dbname$connect) or die ("Could not select database");
        return 
$connect;
}

function 
getSomething(){

 
$connect makeConnection();

 
$query "SELECT username, alias, real_name, text, mail FROM users";

 
$result mysql_query($query$connect);

    while(
$row mysql_fetch_assoc($result)) {
        
$details[] = $row;
        }
  return 
$details;
}

$userlist getSomething();

?>
List of MySQL-functions onb PHP :
http://fi2.php.net/manual/en/ref.mysql.php

Last edited by onjoo; 02-14-2006 at 02:59 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
php-mysql dependancy problem after nitemare mysql upgrade. RHEL4 andrewc Red Hat 1 01-03-2006 04:16 PM
mysql-server4.1 and mod php-mysql conflig kernelvn *BSD 0 06-18-2005 11:52 AM
Problem getting PHP to recognize MySQL, Using PHP 4.0 and MySQL 4.0.20 d2army Programming 4 06-27-2004 08:54 PM
php4 mysql, installation, php-pages with mysql info stay empty dnla Linux - Software 2 03-14-2004 02:54 PM
Apache Mysql Php: mysql with php doesn't work breakerfall Linux - Networking 6 12-27-2003 08:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration