Forum Moderators: coopster

Message Too Old, No Replies

"local host" "user" "password"

I can't figure out what my local host is.

         

kevinoneill

5:46 am on Oct 3, 2005 (gmt 0)

10+ Year Member



I'm new to PHP/MySQL, I recently just got a server to host my site with PHP/MySQL so I could learn.

I'm using a few tutorial pages just to try to get some working stuff up. But I'm getting nothing but errors back. My PHP docs can't find my MySQL databases. And frankly, I can't either.

I have created a Db both threw myAdminPHP (CPanel) and also tried using a tutorial that created the base/table for me.

What is the local host? The address of where my Db is? I use an FTP program, should I be able to find my Db among my folders? Is it saved server side, to where I won't see it?

I've been trying to no avail for a week now to figure something out. When your lost, you are lost.

mysql_pconnect("localhost","user","pass");
mysql_select_db("db name");

R e b r a n d t

6:44 am on Oct 3, 2005 (gmt 0)



The first parameter of mysql_connect() function is server name/IP. Sometimes it is "localhost" (if the server and php application are on the same machine, localhost stands for 127.0.0.1). In your case you should ask/get mysql credentials (server name/ip, login and password) from the company/organization/person who provided you hosting.

Also, the error message would help too.

kevinoneill

2:16 pm on Oct 3, 2005 (gmt 0)

10+ Year Member



As of right now, no error is showing, using what I've shown. Would that suggest my Db is set up wrong?

When I create a Db or username threw myAdminPHP it changes the name slightly. if i enter ireKevin for user name, it will display irekevin_irekevi, same thing with the Db, I call it ireKevin, it displays ireKevin_

Sugguestions?

SHOUTBOX.PHP

<?php

mysql_pconnect("localhost","irekevin_irekevi","my_password");
mysql_select_db("shoutbox?");

if($submit) {
$time = date("d.m.Y., H:i ");
$result = mysql_query("
INSERT INTO
shoutbox
SET
message = '$message',
name = '$name',
time = '$time'
");
header("Location: viewshoutbox.php");
}
?>

VIEWSHOUTBOX.PHP

<html>
<head>
<title>Shoutbox</title>
</head>
<body>

<!--forma za upis-->
<form action="shoutbox.php" method="post">
<input type="text" value="name/nick" name="name">
<input type="reset" name="Reset" value="clear">
<br>
<input type="text" value="message" name="message">
<input type="submit" name="submit" value="shout!">
</form>

<?php

mysql_pconnect("localhost","irekevin_irekevi","my_password");
mysql_select_db('shoutbox');

$result = mysql_query("
SELECT
*
FROM
shoutbox
ORDER BY
id DESC
LIMIT 20
");

while($a>$b) {
$c++;
}

?>
</body>
</html>

kevinoneill

3:24 am on Oct 4, 2005 (gmt 0)

10+ Year Member



I believe I'm connecting fine, but something is maybe wrong with my PHP. I get no errors, thats why I'm assuming I have the correct localhost, username, password, Db name, Table name...

Am I missing PHP that will write the Db Content, or code that will write to the table? Maybe missing some `` or ' ' or " " or?

Suggestions?

compose

7:26 am on Oct 4, 2005 (gmt 0)

10+ Year Member



Hi,

I think u are facing problem because u not passed second parameter of mysql_select_db() that is "link_resource_identifier".

Ur Code
==========
mysql_pconnect("localhost","irekevin_irekevi","my_password");
mysql_select_db('shoutbox');

Replace With This
===================
$db = mysql_pconnect("localhost","irekevin_irekevi","my_password");
mysql_select_db('shoutbox',$db);

Vineet

dmmh

10:47 am on Oct 4, 2005 (gmt 0)

10+ Year Member



personally I am more of a fan having my login credentials in an include, so I only have to change it once and its accepted side wide

just an idea

also, I think a @ is very usefull here, what if there is a time the script can not connect to the DB?
It will echo out your full login credentials to the browser if you dont surpress the error!
I dont think this is what anyone wants :)

<? @ $db = mysql_connect('localhost', 'mysql_user', 'mysql_pass');?>

dmmh

10:50 am on Oct 4, 2005 (gmt 0)

10+ Year Member




I think u are facing problem because u not passed second parameter of mysql_select_db() that is "link_resource_identifier".

the link resourcr identifier is totally optional ;)

[nl3.php.net...]


link_identifier

The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level warning is generated.

jatar_k

3:28 pm on Oct 4, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



yes, the second var in select db is not needed but compose you got the error anyway

$db =mysql_pconnect("localhost","irekevin_irekevi","my_password");

the connect function returns a connection, you need to store it in a var

also I would use mysql_connect not mysql_pconnect unless you already uncerstand a reason why you might need pconnect.