Solved

SQL server 2008 connction to a website -  how is the connection made?

Posted on 2012-04-06
15
364 Views
Last Modified: 2012-08-13
Hi:
My company has a website that connects to SQL server 2008.
The website interface using PHP/MySQL.  It is actually just  a WordPress modified/customized site.

so we have:
"website" <------> SQL server.

Basically,
1  - where is the connection initializes, in SQL server calling requesting the website? Or the connection code (or "string") withing the  WordPress code, calling SQL server?

2- If from the website, where do you put that connection code?
    If from SQL server, where do you do it in SSMS or what is the T-SQL to make the connection.

As you can see from this, I am new to the process, so please use simple English.

Thanks very much.
0
Comment
Question by:noamco36
  • 8
  • 7
15 Comments
 
LVL 70

Assisted Solution

by:Jason C. Levine
Jason C. Levine earned 500 total points
Comment Utility
>> Or the connection code (or "string") withing the  WordPress code, calling SQL server?

Yes.  You set the access details (server name, username, password, database name) in wp-config.php but the actual calls are in the code.  There are Wordpress functions  ( wp_db() ) that serve as the bridge between the theme and the core.

>> If from the website, where do you put that connection code?

Wherever it needs to be.  In a typical PHP script you make the database connection before you interact with the database and close the connection when you are done.  If you want to make a persistent connection, you would add that code as an include for all files that need to touch the database.
0
 

Author Comment

by:noamco36
Comment Utility
" You set the access details (server name, username, password, database name) in wp-config.php"

What about if the website access more than one DB which "lives" on SQL server,
would it be like this:  You set the access details (server name, username, password, database name1;database name2;database name3) ?
0
 
LVL 70

Assisted Solution

by:Jason C. Levine
Jason C. Levine earned 500 total points
Comment Utility
No.  WordPress core is on one database only.  If you are extending WordPress and need to add more databases for plugins or alternately functionality you would then write new connection strings in that specific code.
0
 

Author Comment

by:noamco36
Comment Utility
So you mean if the website is retreaving data from multiple dbs, you will have to code WordPress like this?:

(server name, username, password, database name1);
(server name, username, password, database name2);
(server name, username, password, database name3)
0
 
LVL 70

Expert Comment

by:Jason C. Levine
Comment Utility
No.  WordPress has its core database and functions to pull data out of the core files.  If you add different databases for different functionality (like custom data for a plugin) then you will need to add connection strings in the custom code you are writing.

If you are talking about mirroring the wordpress database for CDN-style functionality, that's a whole different ball of wax.
0
 

Author Comment

by:noamco36
Comment Utility
you know what I am lost by now.

let me reiterate my question.


viewers who surf the internet connect to the Website.
The website connects to the  data (SQL server).
The Data is fed into the website, and the website make the data available for viewers.

How does that work.
Where is the connection b/w the website and data server being make, and how.

Laymans terms please.

Thanks.
0
 
LVL 70

Assisted Solution

by:Jason C. Levine
Jason C. Levine earned 500 total points
Comment Utility
>> How does that work.

The code of the web site queries the database and returns the results.

>> Where is the connection b/w the website and data server being make, and how.

In the server-side code that runs the web site. For instance WordPress does it with PHP.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:noamco36
Comment Utility
ok, so what would the code look like or what you programmers call "connection string", on the PHP server?

((For instance, lets say the SQL server name is "CompanySQLserver" and the database name is "WebsiteDB")))
0
 
LVL 70

Expert Comment

by:Jason C. Levine
Comment Utility
http://www.php.net/manual/en/mysqli.construct.php

This is an example for PHP connecting to MySQL.

<?php

$mysqli = new mysqli('CompanySQLserver', 'my_user', 'my_password', 'WebsiteDB');

if ($mysqli->connect_error) {
    die('Connect Error (' . $mysqli->connect_errno . ') '
            . $mysqli->connect_error);

echo 'Success... ' . $mysqli->host_info . "\n";

$mysqli->close();
?>

Open in new window

0
 

Author Comment

by:noamco36
Comment Utility
Ok, so lets say the above code was "removed", what would the views see on their browser?

"Page cannot be displayed" or some other error?
0
 
LVL 70

Assisted Solution

by:Jason C. Levine
Jason C. Levine earned 500 total points
Comment Utility
It would depend on the rest of the code, what is stored in the database,  and how good the error trapping is.  

If I do a site that is mainly static HTML and CSS but pulls some content from the database to display to users, removing the connection string would prevent just that content from showing but the page would otherwise render.  If the database is storing user preferences, login status, content, etc., then removing the database may cause the whole page to fail and the error trapping would determine what the user sees.
0
 

Author Comment

by:noamco36
Comment Utility
" If the database is storing user preferences, login status, content, etc.,"
Does that mean that some databases store within their tables "website users log on ids for the besite" itself?

In other words, I connect to a website and within that site there is a "LonIn" link.
I press on that link and it asks for my User name and password. Is that user name and password stored on the SQL server? Or within the website?
0
 
LVL 70

Assisted Solution

by:Jason C. Levine
Jason C. Levine earned 500 total points
Comment Utility
>> Is that user name and password stored on the SQL server?

It is usually stored in the database.  Without the database, a dynamic site doesn't function.  So even though there are two different servers involved (web and database) they are tightly integrated.
0
 

Author Comment

by:noamco36
Comment Utility
that makes sense.
So can we say that any website that takes information in from viewers  and stores it somewhere (on the SQL server database tables) is considered a "dynamic site",
and every website that is just informational, with no viewer interaction, is called a "static site"?
0
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 500 total points
Comment Utility
Not quite correct.  Every site takes in information from viewers passively via server logs (IP address, pages viewed, where they came from, etc.) so your definition is not really making a distinction nor is a database necessarily involved.  "Viewer interaction" is also something that always happens on a site in the form of clicks.  All sites are informational :)  

A better definition is:

A dynamic site is one that changes what is displayed to users based on information or preferences detected and/or uses a database to store all content and displays the content via database queries.  A static site only shows the HTML and CSS content as put in the page and does not change or adapt itself to the specific user.


So by the above definition, you could have a dynamic site that uses javascript for the "dynamic" actions and no database is required and still be a dynamic site.  Databases just make things a lot easier and also allows you to separate your content from your design.  Bringing the conversation full-circle, that's what WordPress attempts (largely successfully) to do.  All of the content is kept in a database but the design (theme) can be changed at will and as long as the theme is coded to standards then any theme will work properly.
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Suggested Solutions

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now