Leshiy Posted January 20, 2007 Share Posted January 20, 2007 Hi there, I am new to php. SO I have downloaded few examples and all that and have set up apache server and mysql server on my linux box. Independently everything seem to work fine. However when I try and connect and run simple query I get no where. Is it because I am trying to connect to the "wrong place"Here is some code I have used:[code]<?php$mysqluser = 'user';$mysqlpasswd = 'passwd';$mysqlhost = 'localhost';$connID = mysql_connect($mysqlhost, $mysqluser, $mysqlpasswd);$result = mysql_list_dbs();echo "<p>Databases in the local MySQL server</p>\n";echo "<p>";while ($row = mysql_fetch_row($result)) { echo "<br><em>$row[0]</em>\n";}echo "</p>";?>[/code]Unfortunately I just get empty page with no results. Mysql is running on my machine and I can access it, creat and drop tables via command line.Any thoughts on why i can't do the same via php/internet?Thanks Alex Quote Link to comment Share on other sites More sharing options...
sinbad Posted January 20, 2007 Share Posted January 20, 2007 Hi there,Have you checked that you have specified the database name, username, and password in your php script? Quote Link to comment Share on other sites More sharing options...
Leshiy Posted January 20, 2007 Author Share Posted January 20, 2007 Yeah the user I have used above is valid user in mysql database and i am using same password as in command line. I haven't specified any other names because I am just trying to pull out list of all tables in the database. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted January 21, 2007 Share Posted January 21, 2007 [code]<?php$mysqluser = 'user';$mysqlpasswd = 'passwd';$mysqlhost = 'localhost';$connID = mysql_connect($mysqlhost, $mysqluser, $mysqlpasswd);$result = mysql_list_dbs();echo "<p>Databases in the local MySQL server</p>\n";echo "<p>";while ($row = mysql_fetch_row($result)) { echo "<br><em>$row[0]</em>\n";}echo "</p>";?>[/code]First off you are trying to run, before you walk. First get the connection, forget about list db's first.Simply domysql_connect and mysql_select_db, using hte username/password you specified, lieke thismysql_connect("localhost", "username", "password");mysql_select_db("db_name");echo mysql_error();keep it simple, then you know whether or not you are even connected in the first place.If you are, then start working with list db's, if you raen't give us the error message.If no error message returns or outputs to the page, then you are connected. Quote Link to comment Share on other sites More sharing options...
Leshiy Posted January 21, 2007 Author Share Posted January 21, 2007 Here is what I got:[code]echo 'debug 1';mysql_connect("localhost", "alex", "user");echo 'debug 2';mysql_select_db("mysql");echo mysql_error();[/code]The only thing that is displayed is "debug 1" ..... so I presume I didn't manage to connect to mysql serverI have tried different varietions of localhost, 127.0.0.1,127.0.0.1:3306 same output. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted January 22, 2007 Share Posted January 22, 2007 Ok, if that is the case, you are not making a connection. What webhost do you have, call them adn see if you are suppose to use "localhost" or if it's different with that host, it's not always localhost, but it is most of the time. Make sure what it is real quick then double check your username/password. Quote Link to comment Share on other sites More sharing options...
Leshiy Posted January 22, 2007 Author Share Posted January 22, 2007 I am hosting it on my desktop at the moment for developing. I presume I have not setted it up correct in the first place then. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.