Jul 26, 2008

Connect To Sql (read Note) - You Can Connect To MY Sql With PHP

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Connect To Sql (read Note) - You Can Connect To MY Sql With PHP

farsiscript
hi all
this is my first Tut
i hope you enjoy it
At first Open Notepad.exe
then write this code ::
CODE
<?php
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("news") or die(mysql_error());
?>

And Save it With Connect.php name
With that code you can connect to MySql to manage (add/Delete/Update) Row or .....
and now we talk about that code :
<?php <------------- at first line php is begin ------------- >

mysql_connect("localhost","username","password") or die(mysql_error());

localhost :: where is your sql ! if your sql in your CPanel You must write localhost
Username :: like username
password :: like sql password

mysql_select_db("databasename") or die(mysql_error());
Databasename = Your database name
* if Your domain is asd.com and then you make news database your database name = asd_news

?> <------------- end of php ------------- >
with this script you can just connect to database for read / write / delete / update you must user query

have good time

Notice from saint-michael:
do not accept this tutorial since this tutorial is more for larger php/mysql scripts that require this connection script to be used.

 

 

 


Reply

lefos
I use this as a script for noobs, it works easy


CODE
mysql.php

$server = "localhost"; //Deafault is localhost, only change if you are using this script remotely
$user = "root"; //mysql user
$password = ""; /mysql pass
$database="db"; //databse

#############################
####DO NOT EDIT BELOW THIS LINE####
############################
mysql_connect($server, $user, $pass) or die("Could not connect to mysql: ".mysql_error());
mysql_select_db($database) or die("Could not connect to mysql database: ".mysql_error());


then in any page you want to use, as long as it is in the same folder, do
CODE

<?php include("mysql.php"); ?>
<html> <body>page here</body</html>

 

 

 


Reply

farsiscript
Yes In big CMS Connecting To Database In One File and an other File include Database File
its mean don't write 20 line code for every page .
In Big CMS this File name is config.php some times setup.php or db.php
but config.php is popular

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : sql sql php


    Looking for connect, sql, read, note, connect, sql, php

Searching Video's for connect, sql, read, note, connect, sql, php
advertisement



Connect To Sql (read Note) - You Can Connect To MY Sql With PHP



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE