connecting mysql database with php

Status
Not open for further replies.

linux1880

In Runtime
Messages
455
what is the basic i should know about php when connecting the database ? I have finished studing php but being newbie, I would like ask what should I need to know ? I saw that even application forms on html can be sent to mysql with javascript, can anybody enlight this to me on the basics , any help is appreceated. Thank you.
 
Code:
<?php
$host = 'localhost'; // MySQL host name
$user = 'root'; // MySQL database user name
$pass = 'root'; // MySQL database user password
$db = 'dbname'; // MySQL database name

$connect = @mysql_connect ($host,$user,$pass) or die ('Error connecting to database!');

$select = @mysql_select_db ($db) or die ('Error selecting database!');
?>

Now you are connected to MySQL. Save this file as mysql.php or something and include it on every page that needs a MySQL connection.

As for Javascript accessing MySQL, that is called AJAX and you need a pretty good knowledge of Javascript and XML before you get into that.
 
Status
Not open for further replies.
Back
Top Bottom