Jump to content
xisto Community
Sign in to follow this  
farsiscript

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

Recommended Posts

hi all

this is my first Tut

i hope you enjoy it

At first Open Notepad.exe

then write this 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.

Share this post


Link to post
Share on other sites

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


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
<?php include("mysql.php"); ?><html> <body>page here</body</html>

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.