LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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-14-2006, 12:06 AM   #1
shipon_97
Member
 
Registered: Oct 2005
Location: Bangladesh
Posts: 484

Rep: Reputation: 30
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-14-2006, 12:47 AM   #2
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,275

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
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, 03: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 03:59 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 05:16 PM
mysql-server4.1 and mod php-mysql conflig kernelvn *BSD 0 06-18-2005 12:52 PM
Problem getting PHP to recognize MySQL, Using PHP 4.0 and MySQL 4.0.20 d2army Programming 4 06-27-2004 09:54 PM
php4 mysql, installation, php-pages with mysql info stay empty dnla Linux - Software 2 03-14-2004 03:54 PM
Apache Mysql Php: mysql with php doesn't work breakerfall Linux - Networking 6 12-27-2003 09:59 PM


All times are GMT -5. The time now is 07:57 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration