Db - config.php help
Moderator: General Moderators
Db - config.php help
I wanne make a basic config.php with db username and password and the database and so on ... and i wanne then use "Select" statment but i am sort of new to php .. could some one please help me out or show me a url of a toturliel that can help me out or any thing .. please
Thanks
Thanks
I got this now but its not working and i have no idea what it is not working can any one please help me out with the problim i would really be great full
// create connection; substitute your own information
$conn = mysql_connect("localhost","root","root");
// select database; substitute your own database name
$db = mysql_select_db("phpatlas", $conn);
$sql = "SELECT id, testfield FROM test";
$result = mysql_query($sql,$conn);
$setinfo = mysql_fetch_row($result);
echo "$setinfo[testfield]";
// create connection; substitute your own information
$conn = mysql_connect("localhost","root","root");
// select database; substitute your own database name
$db = mysql_select_db("phpatlas", $conn);
$sql = "SELECT id, testfield FROM test";
$result = mysql_query($sql,$conn);
$setinfo = mysql_fetch_row($result);
echo "$setinfo[testfield]";
-
microthick
- Forum Regular
- Posts: 543
- Joined: Wed Sep 24, 2003 2:15 pm
- Location: Vancouver, BC
try this may b u have some problem in conecting to ur database
Code: Select all
mysql_connect ($host, $uname, $pass) or die ('I cannot connect to the database because: ' . mysql_error());There is information in the database ... this script just gives me a blank page and i cant anderstand why.
// create connection; substitute your own information
$conn = mysql_connect ("localhost", "root", "root") or die ('I cannot connect to the database because: ' . mysql_error());
// select database; substitute your own database name
$db = mysql_select_db("phpatlas", $conn);
$sql = "SELECT id, testfield FROM test";
$result = mysql_query($sql,$conn);
$setinfo = mysql_fetch_row($result);
$testfield = $setinfo["testfield"];
echo "$testfield";
database base
id testfield
1 213123
// create connection; substitute your own information
$conn = mysql_connect ("localhost", "root", "root") or die ('I cannot connect to the database because: ' . mysql_error());
// select database; substitute your own database name
$db = mysql_select_db("phpatlas", $conn);
$sql = "SELECT id, testfield FROM test";
$result = mysql_query($sql,$conn);
$setinfo = mysql_fetch_row($result);
$testfield = $setinfo["testfield"];
echo "$testfield";
database base
id testfield
1 213123
I found this from a irc help and it works so i am going to use this now ... thanks guys.
mysql_connect("localhost", "root", "root") or
die("Could not connect: " . mysql_error());
mysql_select_db("phpatlas");
$result = mysql_query("SELECT id, testfield FROM test");
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
printf("ID: %s Name: %s", $row[0], $row[1]);
}
mysql_free_result($result);
mysql_connect("localhost", "root", "root") or
die("Could not connect: " . mysql_error());
mysql_select_db("phpatlas");
$result = mysql_query("SELECT id, testfield FROM test");
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
printf("ID: %s Name: %s", $row[0], $row[1]);
}
mysql_free_result($result);
Amm i found this script also and i was wondering how would i use this now for a select statemet , please help ...
<?php
function connect_db() {
$db_server = 'localhost';
$db_user = 'root';
$db_password = 'root';
$db_database = 'phpatlas';
$dbi = mysql_connect($db_server, $db_user, $db_password) or die(mysql_error());
mysql_select_db($db_database);
return $dbi;
}
if (!isset($dbi)) $dbi = connect_db();
?>
<?php
function connect_db() {
$db_server = 'localhost';
$db_user = 'root';
$db_password = 'root';
$db_database = 'phpatlas';
$dbi = mysql_connect($db_server, $db_user, $db_password) or die(mysql_error());
mysql_select_db($db_database);
return $dbi;
}
if (!isset($dbi)) $dbi = connect_db();
?>
Code: Select all
<?php
function connect_db() {
$db_server = 'localhost';
$db_user = 'root';
$db_password = 'root';
$db_database = 'phpatlas';
$dbi = mysql_connect($db_server, $db_user, $db_password) or die(mysql_error());
mysql_select_db($db_database);
return $dbi;
}
if (!isset($dbi))
$dbi = connect_db();
$sql = "SELECT id, testfield FROM test";
$result = mysql_query($sql,$dbi);
$setinfo = mysql_fetch_row($result);
//rest sameas u did
Last edited by phpcoder on Tue Jan 20, 2004 11:53 am, edited 1 time in total.
just put this function in ur file and call this function and then apply any query that u want. i think u asked i have this function how u would use its for select statementdoggy wrote:Amm i found this script also and i was wondering how would i use this now for a select statemet , please help ...
<?php
function connect_db() {
$db_server = 'localhost';
$db_user = 'root';
$db_password = 'root';
$db_database = 'phpatlas';
$dbi = mysql_connect($db_server, $db_user, $db_password) or die(mysql_error());
mysql_select_db($db_database);
return $dbi;
}
if (!isset($dbi)) $dbi = connect_db();
?>
It seems like you're having a lot of trouble. You should go back and read about the proper way to connect to a database and how exactly to use and execute SQL expressions.
http://www.devshed.com/c/a/MySQL/Beginn ... -Tutorial/
http://www.php.net/manual/en/ref.mysql.php (Scroll down to the examples)
Here is how I make a database connection:
http://www.devshed.com/c/a/MySQL/Beginn ... -Tutorial/
http://www.php.net/manual/en/ref.mysql.php (Scroll down to the examples)
Here is how I make a database connection:
Code: Select all
<?php
@mysql_connect($host,$user,$password) or die("Unable to connect to MySQL database: " . mysql_error());
@mysql_select_db($this->db) or die( "Unable to select MySQL database.");
$query = "SELECT * FROM table WHERE foo='$bar'";
$result = mysql_query($query) or die("MySQL query failed: " . mysql_error());
?>