Page 1 of 1

Configuring MySQL in PHP

Posted: Thu Apr 18, 2002 5:17 pm
by timbo
I have downloaded and installed PHP successfully on my PC running Windows NT using the Windows installer version rather than compiling source. The basic PHP commands seem to be working. However MySQL does not seem to be working from within PHP...

The symptoms are that the mysql_connect( ) and mysql_select_db( ) are completing OK but actual SQL done via mysql_query( ) is returning false result (no error though).

I downloaded MySQL separately and can run mysqladmin and the DOS interface where I can create tables and query them.

I notice in the PHP documentation that from PHP4 has MySQL "built into PHP". There are also comments about having to tell PHP where the MySQL implementation is if you do not want to use the built in version. But how do you do this? I can't work out where to put the directive to tell PHP to use MySQL in the c:/mysql directory or even if I need to do this...

Help! Anyone got any ideas/answers?

Posted: Thu Apr 18, 2002 11:23 pm
by sam
Well because the mysql_connect() and mysql_select_db() are working I would venture to say that you most likely have an error in your SQL statement. If you post it we might be able to give you some help.

Cheers Sam

Example of SQL failing

Posted: Fri Apr 19, 2002 6:16 am
by timbo
As requested here is an example of the PHP code that is not working. It prints allthe connection stuff but then prints the "No MySQL result"

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Do MySQL 2</title>
</head>

<body>

<?PHP
	$DB_HOST = "localhost";
	$DB_USER = "root";
	$DB_PASSWORD = "fenton";
	$db_link = mysql_connect( $DB_HOST, $DB_USER, $DB_PASSWORD ) or die("cannot connect to MySQL");
	print("Connected to MySQL
");

	$DB_NAME = "mysql";
	mysql_select_db($DB_NAME, $db_link) or die("cannot select 'mysql' database"); 
	print("<br>'mysql' selected");

	$sqlstring = "CREATE TABLE test (test_id smallint(6) DEFAULT '0' NOT NULL auto_increment, test_text tinytext NOT NULL, PRIMARY KEY (test_id))";

	$result = mysql_query( $sqlstring, $db_link );

	if ( $result ) &#123;
		print("<br>MySQL instruction executed:<br>$sqlstring");
	&#125; else &#123;
		print("<br>No MySQL result... <br>$sqlstring
");
	&#125;

?>
</body>
</html>
Could it be an authority issue? How do I look at the MySQL settings for the default PHP MySQL settings?

Posted: Fri Apr 19, 2002 11:04 am
by sam
SELECT * FROM mysql.user; will show you the list of users, if you run a GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY 'fenton' WITH GRANT OPTION; It will enable you to set the access limitations of your user account.

Cheers Sam...

Posted: Fri Apr 19, 2002 12:05 pm
by jason
You might also try printing out what mysql_error() returns.

Posted: Sat Apr 20, 2002 3:53 am
by hex
Also, why not use the command line interface to add tables and stuff? Or even better than that, get the glorious phpMyAdmin:
http://www.phpwizard.net/projects/phpMyAdmin/index.html
http://phpmyadmin.sourceforge.net/
http://www.phpmyadmin.net/