473,324 Members | 2,313 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Code stops executing at mysql_connect(

Hi All

I am new to PHP and MySQL, so please go easy on me!

The following is a simple PHP script to connect to my server. The MySQL service is running. The first echo statement displays, but the second one never displays. To me it implies that my connection to the database server is hanging, but I'm not sure what to look at. I don't even get an error, it just displays the first message and the second message never appears.

<html>
<head><title>Create Database and table</title></head>
<body>

<?php

echo "Before";
$linkID = mysql_connect("localhost","martin","martin");
echo "After";

?>
</body>
</html>
Jan 4 '07 #1
10 5460
Try changing the second parameter (username) "Robert" to "root".


Shaffer.
Jan 4 '07 #2
cassbiz
202 100+
There are many good tutorials out there.

http://www.freewebmasterhelp.com/tutorials/phpmysql

In your above code you are asking to connect to a DB but only supplying the location, user and pass. Not asking for anymore, no query.

Read up on some of the tutorials out there. I myself am new to PHP and MySQL and they have helped me loads.

I still have errors and that is where this forum has helped tremendously.

Good Luck
Jan 4 '07 #3
ronverdonk
4,258 Expert 4TB
Why do you post a MySQL question in the PHP forum?

Before you give up or blame whatever, you should allow MySQL to give you a proper error message. Now you just say "it dies" and you don't even know why. If you would have included proper error handling, you would have received an error message stating the cause. So change your code into this[php]$linkID = mysql_connect("localhost","martin","martin")
or die("Could not connect to the database server: ".mysql_error());
mysql_select_db("db_name",$linkID)
or die("Could not select the database: " . mysql_error());[/php]
Then we'll talk.

Ronald :cool:
Jan 4 '07 #4
ronverdonk
4,258 Expert 4TB
Try changing the second parameter (username) "Robert" to "root".
Shaffer.
Who is Robert? And why to "root"?

Ronald :cool:
Jan 4 '07 #5
Why do you post a MySQL question in the PHP forum?

Before you give up or blame whatever, you should allow MySQL to give you a proper error message. Now you just say "it dies" and you don't even know why. If you would have included proper error handling, you would have received an error message stating the cause. So change your code into this[php]$linkID = mysql_connect("localhost","martin","martin")
or die("Could not connect to the database server: ".mysql_error());
mysql_select_db("db_name",$linkID)
or die("Could not select the database: " . mysql_error());[/php]
Then we'll talk.

Ronald :cool:
Thanks for your prompt reply.

I've posted this question here because I'm not sure if it's something I'm doing wrong with PHP or MySQL or a combination of both.

Even when I try the following piece of code to connect using your suggestion

echo "Test1";
$linkID = mysql_connect("localhost","martin","martin")
or die("Could not connect to the database server: ".mysql_error());
echo "Test2";

I don't get the result of the echo statement straight after the mysql_connect. I even looked at the MySQL Administrator and I also didn't see any new connections being established. I am suspecting it may have something to do with PHP/MySQL configuration, but I haven't been able to figure it out as yet.
Jan 4 '07 #6
Why do you post a MySQL question in the PHP forum?

Before you give up or blame whatever, you should allow MySQL to give you a proper error message. Now you just say "it dies" and you don't even know why. If you would have included proper error handling, you would have received an error message stating the cause. So change your code into this[php]$linkID = mysql_connect("localhost","martin","martin")
or die("Could not connect to the database server: ".mysql_error());
mysql_select_db("db_name",$linkID)
or die("Could not select the database: " . mysql_error());[/php]
Then we'll talk.

Ronald :cool:
Ronlad, thanks for your reply.

I did the following and only the first echo statement printed:

echo "Test1";
$linkID = mysql_connect("localhost","martin","martin")
or die("Could not connect to the database server: ".mysql_error());
echo "Test2";

Any other suggestions? Thanks.
Jan 5 '07 #7
ronverdonk
4,258 Expert 4TB
No, I really don't know. The only reason I can think of is that MySQL is not properly installed or configured. That is all I can think of. I hope there is someone in this forum who can shed some light on this. Sorry.

Ronald :cool:
Jan 6 '07 #8
Ronald, thanks for trying to help me out here.

I've managed to work out what the problem was. When I installed PHP, I didn't install the MySQL extenstion. Unfortunately, when I tried to connect to MySQL from my PHP script, it didn't give me any errors so that's why it was difficult to work out why it wasn't working. Now that I've installed the MySQL extention with PHP, all is working fine. Thanks again.

Thanks to everyone else who also made some suggestions. It was much apprecaited.

Regards
Martin
Jan 6 '07 #9
ronverdonk
4,258 Expert 4TB
I am glad you posted the solution to this problem. You never know who may profit from your experience. You are always welcome in this forum.

Ronald :cool:
Jan 7 '07 #10
JSW321
1
And three years later I have the same problem, was about to go insane, new to php, but have worked with mySQL for 5 years.

Can't thank you guys enough, honest!
Feb 22 '10 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: lawrence | last post by:
Can anyone tell me why this code works in Netscape 7.1 but not in IE??? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) {...
1
by: bennett | last post by:
At http://www.brainjammer.com/testing/validator_test.aspx I have a text field where you can enter text, and a button where if you click the button, it sets the value of a label below it, to...
9
by: BoloBaby | last post by:
I have an extremely vexing problem occurring in a program that I am writing. Consider the following block of code: Dim pDancer As New BEDancer mintIndex = mintIndex + 1 pDancer.DancerName =...
5
by: Adrian Enders | last post by:
I have something that I have never seen before in a MS development product. I have a pretty simple call to a network directory that looks something like this ... Dim dirFolder As...
2
by: Sugapablo | last post by:
I have a small test script connecting to a MySQL database. It seems to work, unless I try to use the resource link identifier returned by mysql_connect(); This works and returns all the rows in...
19
by: Michael | last post by:
Hi, I'm trying to do something which should be very simple - connect to the MySQL database. Here is the call, followed by the error msg. $conn = mysql_connect("localhost", "root", ""); ...
6
by: ste | last post by:
Hi there, I'm just beginning to learn PHP and MySQL, but I'm finding it difficult! I wondered if someone could help me out with a problem I'm having, or at least point me in the right...
14
by: farhan | last post by:
Hi, Please divert me if this is not the right group to be posting this question. I am a Linux client trying to connect to a mysql windows server via php, upon hitting the mysql_connect line...
3
by: leehanson | last post by:
I have a timer function that displays to the user the current number of seconds left for the current question. It all works fine, however when the timer is ticking down, and the user starts to...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.