FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


MySQL Database





riyadh
How do you connect to a database after making a database?

For example I made a database 'games' but aprefix got added to it. I also added a user name and password and a host but don know how to connect to the database in a script i'm using.
Bondings
http://www.php-mysql-tutorial.com/ has a very good tutorial about it. You should take number 4 about connecting to a database. And yes, you should always include your name.
riyadh
I know how to connect to a database but i don know ow the database system works in Frihost. So if u could take me over the ways of making and connecting to a database.
Bondings
You need to go to cpanel --> mysql databases. There you can create a new database and a user with password and then assign that user to the database.

And the database name will be <cpanel name>_<database name> like riyadh_forum .
Aelita
Code:
<?php
$dbhost = 'localhost';
$dbuser = 'USERNAME';//Looks like this   usernamr_USERNAME type exactly how it shows in cpanel
$dbpasswd = 'PASSWORD';//Like this  password
$dbname = 'DATABASE';//your_DATABSE (create in cpanel first)
//This file connects to your database and crestes the necessary
$link = @mysql_pconnect("$dbhost", "$dbuser", "$dbpasswd");
if ($link != TRUE)
{
   echo "Cannot connect to database";
   die(mysql_error());
}

$result = mysql_select_db($dbname, $link);
if ($result != TRUE)
{
   echo "ERROR HERE";
   die(mysql_error());
}

?>


Code:
<?php
include ('connectinfo.php');

//I just pulled this from making the table using phpadmin that why its looks so funny
$sql = 'DROP TABLE `clicks`';
$result = @mysql_query($sql);

$sql = @mysql_query('CREATE TABLE `clicks` ('
        . ' `id` TINYINT NOT NULL AUTO_INCREMENT, '
      . ' `name` TEXT NOT NULL, '
        . ' `url` TEXT NOT NULL, '
        . ' `number` VARCHAR(25) NOT NULL, '
        . ' `type` TEXT NOT NULL,'
        . ' PRIMARY KEY (`id`)'
        . ' )'
        . ' TYPE = myisam');
if ($sql == TRUE)
{
   echo "TABLE ADDED";
   echo "<meta http-equiv=\"refresh\" content=\"5;URL=nowwhat.php\">";

}
else
{
   echo "There has been a problem";
}
mysql_close($link);
?>


Thats a sample scripting of how to connect to a database and even make a table using php scripts
Related topics
Cron Job to Backup MySQL Database
Mysql database problem
PHPBB MYSQL Database Question.
MySQL database for a forum
Mysql database size?
Connect to MySql database
[MySQL database] Password and username
insert data to mySQL database problem
MySQL Database!?
Delete data from MySQL database problem!!
MySQL database
Problem connecting to MySQL database with PHP [RESOLVED]
Need Help with mysql database of DragonflyCMS
Help importing CSV file into MySQL database
How to search in a MySQL - database
Reply to topic    Frihost Forum Index -> Support and Web Hosting -> Web Hosting Support

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.