hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Web Design and Content : Web Design and Content Tutorials : [PHP] Manipulating MySQL (an introduction)
Reply

Web Design and Content Tutorials Tutorials on web design and content.
Forum Jump

[PHP] Manipulating MySQL (an introduction)

Reply Post New Thread In Web Design and Content Tutorials Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 02-27-2006, 04:21 AM
CodyRo CodyRo is online now
Web Hosting Master
 
Join Date: Feb 2006
Location: Buffalo NY
Posts: 1,138

[PHP] Manipulating MySQL (an introduction)


this article is meant for users that have little/no knowledge of how to manipulate MySQL databases via PHP code. Intermediate users might find this useful brush up reading.

the first thing you need to learn is how to open a connection with the MySQL server. this is achieved by PHP's built in function, mysql_connect();

Code:
resource mysql_connect ( [string server [, string username [, string password]]] )
as you can see, the mysql_connect(); function processes 5 parameters when it is accessed. the string server is the MySQL server, on most webhosts and home rigs, this will be localhost. string username is the username required to access your MySQL database. string password is the password used to identify your username. boolean new_link & integer client_flags are the last two but are not necessary to establish a MySQL connection.

following mysql_connect(); usually comes die(); which tells your server what to do incase something goes wrong with the connection. any parameters passed through die(); will output on the .php page.

mysql_error(); returns the text of the error message from previous MySQL operation.

mysql_close(); is used to close a MySQL connection.

here is an example code snippet, opening a MySQL connection.
Code:
<?
    mysql_connect('localhost', 'mysql_user', 'mysql_password');
        or die( mysql_error() );
    mysql_close();
?>
.... more coming, check back for updates
&copy; nuri hodges ( irunbackwards @ phpmydonut.com )


Last edited by CodyRo; 02-27-2006 at 04:30 AM.
Reply With Quote


Sponsored Links
  #2  
Old 03-06-2006, 11:43 PM
Brian-AS Brian-AS is offline
New Member
 
Join Date: Nov 2005
Posts: 3
Nice start so far, how about going another step and telling people how to set up mysql accounts/db's with cpanel/whm? I think that's where a lot of people get tripped up initially.

Reply With Quote
  #3  
Old 03-07-2006, 09:47 PM
CodyRo CodyRo is online now
Web Hosting Master
 
Join Date: Feb 2006
Location: Buffalo NY
Posts: 1,138
as suggested by brian-as, a simple guide to setup a MySQL db using (cPanel 10.8.1-RELEASE-113)

login to your websites cPanel (usually @ domain.com/cpanel)

navigate to "Site Management Tools" & select the option "MySQL Databases"

this will take you to a new page, where cPanel lists your current databases ( and users assigned to these db's ) and a little lower, three forms are available. one to create a MySQL database, one to create a MySQL user, and one to assign a user to a specific database.

go ahead and type in a database name in the form next to "MySQL Database:" and click "Create MySQL Database", this will take you to a confirmation page.

now, return to the MySQL Database manager in cPanel, and scroll down to the form that asks for a username/password, enter in a username with the password, and then click "Create MySQL User", again this will take you to another confirmation page, after you've completed this hit back or re-navigate to the MySQL section of cPanel.

now, to give the user access to a specific database, scroll down to "Grant permissions on a MySQL database to a MySQL user" make sure the checkbox "ALL" is checked to grant uninhibited access to all MySQL commands (you can limit it if you wish by selecting other boxes), and click the button "grant permissions"

congratulations, you have succesfully created a mysql db & user! you can now use them to connect!

&copy; nuri hodges ( irunbackwards @ phpmydonut.com )

more to come....


Last edited by CodyRo; 03-07-2006 at 09:56 PM.
Reply With Quote
Sponsored Links
Reply

Related posts from TheWhir.com
Title Type Date Posted
HP Cloud Services Names Symform Executive Cloud Evangelist Web Hosting News 2013-02-11 10:41:50
Web Host Rackspace Launches Private Beta for MySQL Cloud Database Web Hosting News 2011-12-01 21:09:51
Parallels Now Offering Licenses for CloudLinux OS Web Hosting News 2011-10-26 17:29:25
Web Hosting Software Firm CloudLinux Releases CloudLinux OS Version 6.1 Web Hosting News 2011-09-13 14:08:49
Web Host FireHost Partners with Cloud Security Firm Gazzang for Data Encryption Web Hosting News 2011-08-16 20:33:43


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

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 On
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?