Leaning to work with databases in your PHP starts with understanding on how to connect to the server with PHP. Using only a few lines of code you can easily connect to a database.
define('SQL_SERVER', 'localhost'); // Specify the server address for the MySQL server, localhost is standard define('SQL_USERNAME', 'root'); // Specify server username, replace root with your username define('SQL_PASSWORD', 'password'); // Specify the server password, replace password with your password define('SQL_DATABASE', 'testing'); // Specify the database name, replace testing with your database name // Attempt to connect to the server using the constants(variables) specified above $db = @mysql_connect(SQL_SERVER, SQL_USERNAME, SQL_PASSWORD) or die('Could not connect to the database server'); // Now try connecting to the database in SQL_DATABASE $link = @mysql_select_db(SQL_DATABASE, $db) or die('Could not connect to the database name specified');
In the code above, I have used define() function to create variables of the MySQL server, username, password and database name. I then use these variables in the next lines of code that actually connects to the server.
There are two types of error handling here in this piece of code. The first is the @, placing this before a function hides any kind of error messages that the two functions could display. The second part is the or die() addition at the end of each connect function. Putting this here stops the rest of the code from being executed and shown to the client.
If when you execute this code it does not show any errors, you are then connected to your database server and can use the mysql_query() function or any other mysql function to manipulate your database.





















June 23rd, 2011 at 4:17 am
Temazepam is formally indicated for extreme or debilitating insomnia and other serious or disabling sleep issues. Purchase Temazepam medication.
June 29th, 2011 at 4:22 am
Bring Ambien treatment with a full glass of water. Steer clear of getting Ambien CR with or just soon after a meal or it may possibly consider lengthier for you to drop asleep. Ambien is for quick-term use only. Cheap Ambien online.
August 18th, 2011 at 1:42 am
Its like you read my mind! You appear to know so much about this, like you wrote the book in it or something. I think that you can do with some pics to drive the message home a little bit, but instead of that, this is excellent blog. A fantastic read. I will definitely be back.
September 7th, 2011 at 9:35 am
Very well written article. It will be supportive to anyone who utilizes it, as well as yours truly
. Keep doing what you are doing – can’r wait to read more posts.
December 5th, 2011 at 7:56 am
I found a video of this lady who sounds really nice and talks about some methods that she used to turn her life around and start a new life with a specific income system. Anyway, the video is free so I thought I would provide a link to it here. Also, she does promote an advanced system to use and I noticed that if you close out the page with the video on it, it will ask you to stay on the page for a bonus and if you do, you can get the advanced package for $39 instead of $49. I got enough out of the free video, personally, so I can’t really tell you what the advanced methods are but I think it involves some free traffic secrets and methods that anyone can use. Here’s the link to her video: http://tinyurl.com/bwtaj56