PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 8th, 2012, 09:59 PM
Necrohhh Necrohhh is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 3 Necrohhh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 54 m 34 sec
Reputation Power: 0
PHP5 - PHP + AJAX - Database Connection Test

Hello everyone! I'm so excited I found these forums, I feel like I have a lot to learn here, but anyways, onwards with the question.

I'm looking to make a little CMS for myself to help me out a bit in learning, and just ease of use. I'm in the process of making an installation process, and I'm up to the database connection aspect. I want to use AJAX and PHP to get a connection to the specified $_GET variables filled in, and test to make sure we can connect to the database given. How would I go about checking if the connection was successful?

And how else could I go about doing this other then AJAX if anyone knows?

Thanks to all who help!

- Necro

Reply With Quote
  #2  
Old November 8th, 2012, 11:55 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,944 E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 10 h 16 m 54 sec
Reputation Power: 7053
The only alternative to AJAX is submitting the form to another page as you would normally do.

The most effective way to communicate between JavaScript and PHP is using JSON. PHP provides the json_encode function which allows you to easily transfer data from PHP to JavaScript in response to an AJAX request.

As far as how you would literally go about checking if the connection was successful; you would just use an if statement if you're using mysqli and an exception try/catch block if you're using PDO.

There are really three parts to something like this.
1. In JavaScript, gather the relevant form values and send them to a PHP script using AJAX. This code would likely be located in some sort of submit event handler.
2. In the PHP script, attempt to connect to the database using the submitted values and output a particular value indicating whether the connection was successful or not. This code would use the json_encode function to output the result value in a format that JavaScript can easily understand.
3. In JavaScript, handle the response from the PHP script and update the page markup as necessary to reflect the result of the connection attempt. This code would be located in the callback function for the AJAX request.
__________________
PHP FAQ
How to program a basic, secure login system using PHP
Connect with me on LinkedIn


Quote:
Originally Posted by Spad
Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP5 - PHP + AJAX - Database Connection Test

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap