472,964 Members | 2,408 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,964 software developers and data experts.

Cannot connect to Mysql

Hi, I hope you guys can help me out~~~
when I run it localhost/config.php, it cannot display any message such
as connect successfully or failed. Do u guys have any idea?

config.php
<html>
<head><title>Create Database and table</title></head>
<body>

<?php

$linkID = mysql_connect("localhost","","");
print ("hello"); <---can print
Hello

if($linkID != "FALSE") <--i think
fail here
{
print("The connection to the server was made successfully.)";
}
else
{
print("The connection to the server failed");
}

mysql_close($linkID);

?>
</body>
</html>

am I right? do i need to put username and password in
mysql_connect("localhost","","")? i dont know where i can find it, or
how can I find it in mysql. Hope you guys can help me out~~ Thanks.
Krista
Jul 17 '05 #1
2 4171
Tom
Krista,

If you're using the default installation of MySQL (i.e. you haven't run a
grant statement to create a user), then you're script should have run. You
might want to try augmenting your connection statement with an error output
such as:

$linkID = mysql_connect("localhost","","") or die ('I cannot connect to the
database because: ' . mysql_error());

Tom

"Krista" <yw*****@hotmail.com> wrote in message
news:eb**************************@posting.google.c om...
Hi, I hope you guys can help me out~~~
when I run it localhost/config.php, it cannot display any message such
as connect successfully or failed. Do u guys have any idea?

config.php
<html>
<head><title>Create Database and table</title></head>
<body>

<?php

$linkID = mysql_connect("localhost","","");
print ("hello"); <---can print
Hello

if($linkID != "FALSE") <--i think
fail here
{
print("The connection to the server was made successfully.)";
}
else
{
print("The connection to the server failed");
}

mysql_close($linkID);

?>
</body>
</html>

am I right? do i need to put username and password in
mysql_connect("localhost","","")? i dont know where i can find it, or
how can I find it in mysql. Hope you guys can help me out~~ Thanks.
Krista

Jul 17 '05 #2
Krista wrote:

Hi, I hope you guys can help me out~~~
when I run it localhost/config.php, it cannot display any message such
as connect successfully or failed. Do u guys have any idea?

config.php
<html>
<head><title>Create Database and table</title></head>
<body>

<?php

$linkID = mysql_connect("localhost","","");
print ("hello"); <---can print
Hello

if($linkID != "FALSE") <--i think
fail here
{
print("The connection to the server was made successfully.)";
}
else
{
print("The connection to the server failed");
}

mysql_close($linkID);

?>
</body>
</html>

am I right? do i need to put username and password in
mysql_connect("localhost","","")? i dont know where i can find it, or
how can I find it in mysql. Hope you guys can help me out~~ Thanks.
Yes, you need to put in a username and password, which you should get from your
host. Also, you might want to use the "or die" syntax Tom suggested.
if($linkID != "FALSE") ^^^^^^^^^^ This can be better written as if (!$linkID)

or you could combine your IF and mysql_connect() statements:
if (!mysql_connect("localhost","username","pw"))
echo "Did not connect to DB";

And this line will produce an error if the connection didn't open correctly: mysql_close($linkID);

You can get around that by using the mysql_connect() or die syntax or by
executing the mysql_close only if $linkID is valid. Or, if you're lazy, you
could just code it as @mysql_close($linkID). The "@" keeps any errors from
being written.

Regards,
Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: bettina | last post by:
Hello, My domain: www.coaster.ch My database: coasters User: bettina In the programm I wrote: <?php $db_server = "www.coaster.ch";
0
by: Kyle Goetz | last post by:
hey, i'm new to mySQL...this meaning that i have tried ~10000 times to install it and get it working over the past few weeks...and it always gives me the same error (scroll further down to see it)...
1
by: JW | last post by:
Hi all, I was fine running mysql, and for some reason, after the most recent reboot of my machine, I get the following error and I try the following subsequent commands to try to figure things...
1
by: ikrabbe | last post by:
Hi, I want to set up a mysql server in an embedded process. I managed to start the server in my program as described through mysql_server_init() Now I need a client connection to this...
5
by: MLH | last post by:
I'm supposed to set a password for the MySQL root user. The output of mysql_install_db instructed me to run the following commands... /usr/bin/mysqladmin -u root -h appserver password mynwewpasswd...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
5
by: smatta | last post by:
I have just installed MySql version 5.0-18 on Red Hat Fedora Core 4. It is running but I cant connect to it using MySql Query Browser running on my pc. >From my pc, I can telnet to the sql...
2
by: zMisc | last post by:
I am using VB.NET 1.1 and cannot connect to a MySQL (v5) database. I've done the following: 1) Create a DSN for MyODBC. 2) Connect using: Driver=MySQL ODBC 3.51 Driver; Server=localhost; Data...
5
by: Ike | last post by:
Through Java, I am attempting to connect to a MySQL 4.12 server on a remote computer. I can connect fine via php. I cann connect fine via Java, through a servlet, when the servlet is on the same...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.