LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Php and Mysql (https://www.linuxquestions.org/questions/linux-newbie-8/php-and-mysql-415156/)

shipon_97 02-13-2006 11:06 PM

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 .....

btmiller 02-13-2006 11:47 PM

If you have the php-mysql RPM installed then you can go ahead an use all the mysql_ functions in PHP.

onjoo 02-14-2006 02:56 AM

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


All times are GMT -5. The time now is 12:36 PM.