SmilePHP and Databases #1

Posts 14 of 4 · Page 1 of 1
PHP and Databases #1
Best Forumer,

I want to say beforehand that this tutorial I've written in Dutch, then I got it through google translated into English. Please understand this.

Caution! I make notes and explanations in scripts.

Well I want you to lay out how you can call a database with PHP.
The most common method is to use MySQL. Most hosting sites support this feature.

Chapter 1: Connect to the database

To connect to the database, we use the following code snippet:

[php]<?php
/* Database settings */
$db = array (
'host' => 'localhost', // Hostname
'user' => 'root', // Username
'pass' => '', // Password
'dbname' => 'test' // Database name
);

/* Connect to database */

# Make connection
if(!mysql_connect($db['host'], $db['user'], $db['pass']))
{
// Can't connect!
trigger_error('Error while connecting: '.mysql_error());
}
# Select database
elseif(!mysql_select_db($db['dbname']))
{
// Can't connect database!
trigger_error('Error while selecting database: '.mysql_error());
}
else
{
// Connected to database
// ...
// ...
}
?>[/php]

This was Chapter 1, soon I will go to the next chapter.
:O, Why make a MySQL Based one,
It makes like many more errors then a MsSQL Based one !
Many people use MySQL more so than MsSQL because most free and paid hosts make you use PHPMyAdmin -- MySQL. Although, some hosts do offer the ability to utilize MsSQL. I, personally, prefer MySQL.
Quote Originally Posted by Lost-Shadow View Post
:O, Why make a MySQL Based one,
It makes like many more errors then a MsSQL Based one !
Many people use MySQL instead of MsSQL because MySQL is more flexable. One of the upsides of MySQL is the PHPMyAdmin feature which offers easy database manipulation.
Posts 14 of 4 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?