PDA

View Full Version : Conencting to MySQL Database



geocoins-software.com
07-11-2008, 10:09 PM
Hi,

Im trying to connect to a a mysql database that i created using the console.

I know the database name, user name, and password

I use a PHP Editor (Delphi PHP 2.0) to create my PHP script.

My question is, what is the Host name where the MySQL database i created resides?

Dont laugh.......but i have tried my domain name and the Hostmonster domain, but neither work.

All examples show how to do it using LocalHost

thanks

shane

nerdykit
07-11-2008, 10:26 PM
The host name is usually just that... "localhost" (without the quotes).

geocoins-software.com
07-11-2008, 10:42 PM
i keep getting the following error

Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/geocoins/public_html/test.php on line 12



Do you have an example script that makes a connection to the database?

shadmego
07-12-2008, 12:41 AM
how about you post the lines in your script used to connect to the database, as long as they don't contain any security information like usernames and passwords and we can tell you what to change.

~regards

geocoins-software.com
07-12-2008, 07:57 AM
That is why i asked if anyone had an example script?

>>Do you have an example script that makes a connection to the database?

I use Delphi for PHP 2.0.

thanks

shadmego
07-12-2008, 08:04 AM
um ....

here is one way:



<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

$dbname = 'petstore';
mysql_select_db($dbname);
?>


But it looks like, from your error, that you are missing part of the syntax: "}" or something else.

The problem with helping you this way is that there are several different ways to connect to a database, depending on what you want to do. Giving you and example of how to do it not knowing what your script looks like is not an incredibly effecient way of helping, but there is an example none-the-less.

~regards

geocoins-software.com
07-12-2008, 08:45 AM
Hi,

Thank you, that helps!


Sorry for being so naive, but how do you hide the user name & password from others viewing it

thanks

geocoins-software.com
07-12-2008, 09:01 AM
ahhhhhhhhhh, never mind....when i embed the php code in HTMl and then view the html source, the script is not viewable...

<smile>

thanks

pghcollectibles
07-12-2008, 10:49 AM
i get similar errors like the one you gave when i forget a ; or quotes or some other form of syntax normally hense the syntax error

and the name user password and file structure are all case sensitive