November 6th, 2013, 01:22 PM
SQL connection string
Hi Guys Im creating my own website and I have never connected via SQL before only bu using MS Access.
I'm using Heart Internet and Joomla (I'm hard coding this as I'm looking for my first graduate job)I take it with the variables I have to define where my site is, what the name of the website is and the user name and password of the backend of the SQL database?
<?php # Script 7.2 - mysql_connect.php
// This file contains the database access information.
// This file also establishes a connection to MySQL and selects the database.
// Set the database access information as constants.
DEFINE ('DB_USER', 'username');
DEFINE ('DB_PASSWORD', 'password');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'sitename');
// Make the connnection.
$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() );
// Select the database.
@mysql_select_db (DB_NAME) OR die ('Could not select the database: ' . mysql_error() );
November 6th, 2013, 02:17 PM
this is a PHP question, not a MySQL question. I'll ask a moderator to move your thread.
Copypasting code from random websites is generally a terrible idea. Most loose PHP code you'll find online is hopelessly outdated, badly written and insecure. That's really not what you want to have on your server, accessible by the whole world.
The code you got there is no exception. It's at least 10 years old, it has no security whatsoever, and it's just crap.
If you want good PHP code, you have to actually learn to program from proper sources. The most obvious and reliable source is the PHP manual. If you search for "mysql_connect", the first thing you'll see is a big red warning box telling you that this function is deprecated and what you should use instead. Follow the links and learn more. While you do that, you'll get plenty of keywords to type into Google and find further information -- like this PHP tutorial for MySQL user.