jimmyc Posted August 16, 2006 Share Posted August 16, 2006 I apologize if this is overly simple but I've had no luck getting it to work nor finding an answer to this.I've installed Apache, PHP, MySQL on WindowsXP and they all work. Meaning I can look at php info() and see a nice page, Apache gives me the default page and when I open the MySQL Command Line Client I can connect to the default databases, perform a query, etc. Also, I installed phpMyAdmin and can see the MySQL databases from the phpMyAdmin pages (which are php pages). However I cannot figure out how to "connect" to MySQL from a PHP page.I've used different variations of the following code, but they all yield a blank page. Any idea what I am doing wrong? It seems like this should be the simplest part. And since the phpMyAdmin page sees the databases I really don't get it.This php page is saved to C:/www/test and the databases are located under C:/Program Files/MySQL/MySQL Server 5.0/data<?php$host = "localhost";$user = "root";$pass = "admin";$connect = mysql_connect($host, $user, $pass) or die("Could not connect to mysql server");$sql = mysql_create_db("test1");if (!sql) { echo "there was an error" . mysql_error();}else {echo "database test was created";}Thanks for any help you can provide.-Jim Quote Link to comment https://forums.phpfreaks.com/topic/17762-trouble-connecting-to-mysql-database/ Share on other sites More sharing options...
karthikeyan_coder Posted August 16, 2006 Share Posted August 16, 2006 [code]<?php$host = "localhost";$user = "root";$pass = "admin";$connect = mysql_connect($host, $user, $pass) or die("Could not connect to mysql server");echo("Mysql was connected!<br>");$sql = mysql_create_db("test1");if (!$sql) { echo "there was an error" . mysql_error();}else {echo "database test was created";}mysql_close($connect);?>[/code]User this code and tell me... Quote Link to comment https://forums.phpfreaks.com/topic/17762-trouble-connecting-to-mysql-database/#findComment-75826 Share on other sites More sharing options...
jimmyc Posted August 16, 2006 Author Share Posted August 16, 2006 It prints nothing...blank page. :'(If I put an echo prior to the mysql_connect, that will print on the page fine but it dies just afterward and won't print any other echo statements.<?php$host = "localhost";$user = "root";$pass = "admin";echo $host;$connect = mysql_connect($host, $user, $pass) or die("Could not connect to mysql server"); Quote Link to comment https://forums.phpfreaks.com/topic/17762-trouble-connecting-to-mysql-database/#findComment-75853 Share on other sites More sharing options...
karthikeyan_coder Posted August 16, 2006 Share Posted August 16, 2006 Are you sure... MySql was configured with php/apache?? is Phpmyadmin is working well??? and what about "mysql" category infor in phpinfo() ?? Quote Link to comment https://forums.phpfreaks.com/topic/17762-trouble-connecting-to-mysql-database/#findComment-75874 Share on other sites More sharing options...
jimmyc Posted August 16, 2006 Author Share Posted August 16, 2006 http://localhost/phpMyAdmin works fine. And it lists the databases located under C:\Program Files\MySQL\MySQL Server 5.0\dataI can add a new database, table, anything under phpMyAdmin. But I can't see it from any PHP page that I write.For php info - here is what I get:mysqliMysqlI Support enabledClient API library version 4.1.7Client API header version 4.1.7MYSQLI_SOCKET /tmp/mysql.sockDirective Local Value Master Valuemysqli.default_host localhost localhostmysqli.default_port 3306 3306mysqli.default_pw no value no valuemysqli.default_socket no value no valuemysqli.default_user root rootmysqli.max_links Unlimited Unlimitedmysqli.reconnect Off OffIs mysqli...the "i" a problem?Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/17762-trouble-connecting-to-mysql-database/#findComment-75881 Share on other sites More sharing options...
jimmyc Posted August 16, 2006 Author Share Posted August 16, 2006 Btw, I've tried connecting to the db with or without a password and it yields the same blank page.$host = "localhost";$user = "root";$pass = "";$connect = mysql_connect($host, $user, $pass) or die("Could not connect to mysql server");When I go to http://localhost/phpmyadmin/ I do need to supply the username "root" and password "admin" prior to the page being rendered.Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/17762-trouble-connecting-to-mysql-database/#findComment-75887 Share on other sites More sharing options...
Exussum Posted August 16, 2006 Share Posted August 16, 2006 did you install them all yourself ? or did you use something like WAMP ? Quote Link to comment https://forums.phpfreaks.com/topic/17762-trouble-connecting-to-mysql-database/#findComment-75911 Share on other sites More sharing options...
karthikeyan_coder Posted August 16, 2006 Share Posted August 16, 2006 yes... try wamp server... it is easy to use... http://karthi.livesoft.info/downloads.html Quote Link to comment https://forums.phpfreaks.com/topic/17762-trouble-connecting-to-mysql-database/#findComment-75917 Share on other sites More sharing options...
jimmyc Posted August 17, 2006 Author Share Posted August 17, 2006 Yes, I installed them all myself.I will check out WAMP.Thanks for the advice. ;) Quote Link to comment https://forums.phpfreaks.com/topic/17762-trouble-connecting-to-mysql-database/#findComment-76265 Share on other sites More sharing options...
wildteen88 Posted August 17, 2006 Share Posted August 17, 2006 You are using the wrong extension. If you are using mysql_connect you use the php_mysql.dll extension. Not the php_mysqli.dll extension. The php_mysqli.dll extensions has completly separate functions for that extension which is the mysql[b]i[/b]_*() functions #(note the i before mysql). The mysqli extension will not work with the mysql_*() functions. Quote Link to comment https://forums.phpfreaks.com/topic/17762-trouble-connecting-to-mysql-database/#findComment-76274 Share on other sites More sharing options...
jimmyc Posted August 17, 2006 Author Share Posted August 17, 2006 That was it!!! Thanks very much! ;D ;D :D :DWill keep WAMP in mind for future installations. Thanks!Does something like WAMP exist for Linux (Debian)? Quote Link to comment https://forums.phpfreaks.com/topic/17762-trouble-connecting-to-mysql-database/#findComment-76305 Share on other sites More sharing options...
wildteen88 Posted August 17, 2006 Share Posted August 17, 2006 You can use XAMPP for unix based OS's WAMP stands for Windows Apache MySQL and PHP Quote Link to comment https://forums.phpfreaks.com/topic/17762-trouble-connecting-to-mysql-database/#findComment-76316 Share on other sites More sharing options...
jimmyc Posted August 17, 2006 Author Share Posted August 17, 2006 Great, thank you very much. PHP Freaks rocks! :) Quote Link to comment https://forums.phpfreaks.com/topic/17762-trouble-connecting-to-mysql-database/#findComment-76320 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.