Help - Search - Members - Calendar
Full Version: a question for connect to MySQL database
Hostony Board > General Support > General Support
gg
I create a table, its name is table1, I run this php code(php is saved under wwwroot):

$q=mysql_connect(...);-----------------ok

$ee=mysql_select_db("dbname");----ok




$e=mysql_query("select * from table1");

echo $e;

but it sounds that "mysql_query("select * from table1'");" does not work. I tried to put some thing like ' there, it still does not work. Who knows the basic style for mysql_query() or mysql_db_query();

Thanks.
gg
It is windows OS.
gg
The code is like this:(Windows server)

<?php

$db = mysql_connect("mydomain.org", "created_db_user","password_created");
$e=mysql_select_db("mydomain_is_DB_name",$db);
$result = mysql_query("delete from table table1",$db);
echo $result;

echo $e;

?>

It does not work. Require other setting?
Vanya
Try this
mysql_connect("127.0.0.1", "created_db_user","password_created")
lewis
No, It does not work. I troed every way, it sounds that I am forbidden to run any SQL query to my database in PHP. I think it is because of the setting. If I change to 127.0.0.1, I am even forbidden to access the database no matter I put the password there or not. It is not this problem. The problem is that I am denied to run any query in PHP. For example, I am testing a simple query:

<?php

$db = mysql_connect("friendcity.org", "mydatabaseusername","Mypassword") or die ("Problem connecting to mysql"); ;
$e=mysql_select_db("mydatabasename",$db) or die ("Problem connecting to DataBase");

$result = mysql_db_query($db,"select * from my_table") or die ("Problem connecting to query");


echo $e;

?>

The result is: "Problem connecting to query", I tried every kind of query, I am denied to run any query in PHP.
My domain is friendcity.org and I just opened my account.
Vanya
Try this( without last "or die()")

<?php

$db = mysql_connect("friendcity.org", "mydatabaseusername","Mypassword") or die ("Problem connecting to mysql"); ;
$e=mysql_select_db("mydatabasename",$db) or die ("Problem connecting to DataBase");

$result = mysql_db_query($db,"select * from my_table");


echo $e;

?>
lewis
No, even you cancel the show up of the debug information, the point is to let the query work, not just hide the error message. Please run this:

<?php
$db = mysql_connect("friendcity.org", "userxxxx","xxxxxx"); ;
$e=mysql_select_db("databsexxxx",$db);
$result = mysql_db_query($db,"delete from student");

?>

This simple script is already uploaded to: http://www.friendcity.org/index1.php
You can just click this link to run the script. Then you can see admin.friendcity.org
To check the database table "student", all the information are still there, it is not deleted from table "student". That means, although you hide the error message to show but the query still not run. Right now the table "student" is not empty, after you run this index1.php, the table should be empty, but when I checked it, all the data are still there, the table "student" is still the same as before you run this script index1.php.
lewis
continue from last post:

I noticed the windows server started from dec 2003, please check the setting for permission of the database and php. I know this windows server is just setup, if possible, please make sure all the setting on this server is the same as the server of other customer on your windows server WHO IS RUNNING PHP/MySQL under windows environment.
Stanly
Working now smile.gif
lewis
biggrin.gif
No, it is not working. maybe you can test it under my username. I think you are testing it under the username of admin.

This is the simple script:

http://www.friendcity.org/index1.php

It should empty the table "student" in the databse, but after I click the link and then check the table, it is still there without any change. maybe you can test it by using my username and with my setting.Thanks.
lewis
Continue to the last post:

in addition to the last problem, i also find HELM (Control panel) not work for my site.: friendcity.org
Stanly
Working now.
lewis
No, it is NOT working, the databse is still NOT empty.Please see the copy of this:

Aftter I run the script:


<?php

$db = mysql_connect("localhost", "HSTxxx","xxxxxx");


$e=mysql_select_db("friendcity",$db);



$result = mysql_db_query($db,"delete from student");


echo $result;

?>
I get the result:

Showing rows 0 - 1 (2 total, Query took 0.0005 sec)

SQL-query : [Edit] [Explain SQL] [Create PHP Code]
SELECT *
FROM `student` LIMIT 0 , 30


row(s) starting from record #
in horizontal horizontal (rotated headers) vertical mode and repeat headers after cells
Sort by key: name (Ascending) name (Descending) name_2 (Ascending) name_2 (Descending) None
name age score
Liu is very good abnd fghjfgffd
gggfhh
ghgfhhfg
... 22 66
ert 33 10
With selected:
Alec
The script is working after adding of mysql_fetch function in a code.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2024 Invision Power Services, Inc.
IPS Driver Error

IPS Driver Error

There appears to be an error with the database.
You can try to refresh the page by clicking here