read tutorials but they dont tell you where to put the file in your webspace and what to call it as, and how you run the file?
how do you connect to mysql?
Hmm what file u mean? I connect to mysql using PHP most of the time which is simple:
<?php
$link = mysql_connect('mysql_server', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
Put the php script file with the rest of ur web files.
<?php
$link = mysql_connect('mysql_server', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
Put the php script file with the rest of ur web files.
any specific location, then do i execute the file?
also what do i name the file?
also what do i name the file?
Huh?
Are you making your own script or are you stuck on some installation where it wants you to connect to the mySQL Database.
Are you making your own script or are you stuck on some installation where it wants you to connect to the mySQL Database.
First create your database and assign the database user and password. For example:
db name: MonkeyWrench_testdb
db user: MonkeyWrench_dbuser
db password: Secret
(You'll need to set up the tables/fields at this point too)
Create a file (you can call it anything you want, but for this example we'll use the name mysql.inc
In this file put this code in:
This will open a persistent connection to your database and will re-use the MySQL thread instead of creating a new one each page you open.
We put the database code above in it's own file so we lessen the risk of mistyping the info.
Now, in each page that you want to access your database, start out the script with an include to your file. (It needs to be one of the very first things you want to do):
Here's an example of some code I wrote showing how it can be used with sessions:
You don't need to use mysql_close() on every page this way also.
db name: MonkeyWrench_testdb
db user: MonkeyWrench_dbuser
db password: Secret
(You'll need to set up the tables/fields at this point too)
Create a file (you can call it anything you want, but for this example we'll use the name mysql.inc
In this file put this code in:
| Code: |
| <?php
$connect = mysql_pconnect("localhost", "MonkeyWrench_dbuser", "Secret"); if (!$connect){ die(mysql_error()); } mysql_select_db("MonkeyWrench_testdb", $connect); ?> |
This will open a persistent connection to your database and will re-use the MySQL thread instead of creating a new one each page you open.
We put the database code above in it's own file so we lessen the risk of mistyping the info.
Now, in each page that you want to access your database, start out the script with an include to your file. (It needs to be one of the very first things you want to do):
| Code: |
|
<?php include ('mysql.inc'); ... php code here! ... ?> |
Here's an example of some code I wrote showing how it can be used with sessions:
| Code: |
|
<?php session_start(); if ( @$_SESSION['logged'] != "yes" ) { header("Location: login.php"); exit(); } include ('db.php'); ... ?> |
You don't need to use mysql_close() on every page this way also.
the database is
monkeywr_account
but i dont know how to find the database page, i am using php my admin now to edit the database but how do i put a password on it?
monkeywr_account
but i dont know how to find the database page, i am using php my admin now to edit the database but how do i put a password on it?
In cPanel (I assume you are on there because of the joining datE),
you have to create a new user under mysql databses then add it into the database.
A tutorial can be found here - http://frihost.com/forums/vt-19192.html (just read the mysql for cpanel part
).
you have to create a new user under mysql databses then add it into the database.
A tutorial can be found here - http://frihost.com/forums/vt-19192.html (just read the mysql for cpanel part
no, how do i edit the my sql database without using php admin?
Related topics
