SQL select statement doesn't work.

Problems with the Windows version of XAMPP, questions, comments, and anything related.

SQL select statement doesn't work.

Postby Mandee » 07. January 2012 13:37

Hello!I am using version 1.7.4 and facing problem using Sql.
Following are some details:-
MySQL user: root
MySQL password: none
Database: my_db
Table name: persons

I ran the following php code to insert data and it worked successfully:-

<html>
<body>
<?php
$con = mysql_connect("localhost", "root", "");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("my_db", $con);

mysql_query("INSERT INTO persons (firstName, lastName, age)
VALUES ('Peter', 'Griffin', '35')");

mysql_query("INSERT INTO persons (firstName, lastName, age)
VALUES ('Glenn', 'Quagmire', '33')");

echo "Insert command successfully implemented!!!!";

mysql_close($con);
?>
</body>
</html>

After this, I ran following command but it didn't work and gave error:-

<html>
<body>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT firstname,lastname FROM persons");

while(list($firstname,$lastname)= mysql_fetch_row($result))
{
echo $row['firstname'] . " " . $row['lastname'];
echo "<hr>";
}

mysql_close($con);
?>
</body>
</html>


Following is the warning received:-
Warning: mysql_connect() [function.mysql-connect]: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\xampp\htdocs\test\select.php on line 4
Could not connect: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

I was able to execute " select * from persons; " in query window in localhost/phpMyAdmin.

Could you please tell me the reason and some solution to overcome this problem??
Mandee
 
Posts: 1
Joined: 07. January 2012 12:39
Operating System: Windows XP Professional SP2

Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 94 guests