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

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.
noamco36Asked:
Who is Participating?
 
Jason C. LevineNo oneCommented:
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
 
Jason C. LevineNo oneCommented:
>> 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
 
noamco36Author Commented:
" 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
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
Jason C. LevineNo oneCommented:
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
 
noamco36Author Commented:
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
 
Jason C. LevineNo oneCommented:
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
 
noamco36Author Commented:
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
 
Jason C. LevineNo oneCommented:
>> 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
 
noamco36Author Commented:
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
 
Jason C. LevineNo oneCommented:
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
 
noamco36Author Commented:
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
 
Jason C. LevineNo oneCommented:
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
 
noamco36Author Commented:
" 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
 
Jason C. LevineNo oneCommented:
>> 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
 
noamco36Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.