| | |
Need Assitance On Php & Mysql test.
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Sep 2008
Posts: 3
Reputation:
Solved Threads: 0
I was following this tut. on how to install Apache, PHP, Mysql, and PHPmyadmin. I need a bit of help! I get a "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\mysql_test.php on line 15" everytime I test the mysql thing.
What ive done so far is :
The author of the tutorial told me to write and save this in the htdocs.
replacing the " password " with my password?
The tutorial link is here : http://www.bicubica.com/apache-php-mysql/index.php
What ive done so far is :
Configuring PHP to work with MySQL:
Now that both PHP and MySQL are installed, we have to configure them to work together.
1. Open up your php.ini file (C:/WINDOWS/php.ini) and find the line:
;extension=php_mysql.dll
To enable the MySQL extension, delete the semi-colon at the beginning of that line.
2. Next we must add the PHP directory to the Windows PATH. To do this, click: Start > My Computer > Properties > Advanced > Environment Variables. Under the second list (System Variables), there will be a variable called "Path". Select it and click "Edit". Add ";C:\php" to the very end of the string and click "OK".
3. Restart your computer for the changes to take effect.
4. Create a new file in your "htdocs" directory called "mysql_test.php".
5. Copy the following code into "mysql_test.php" and click save. (Make sure to replace the MYSQL_PASS constant with the MySQL Password you specified during the MySQL installation).
<?php
# Define MySQL Settings
define("MYSQL_HOST", "localhost");
define("MYSQL_USER", "root");
define("MYSQL_PASS", "password");
define("MYSQL_DB", "test");
$conn = mysql_connect("".MYSQL_HOST."", "".MYSQL_USER."", "".MYSQL_PASS."") or die(mysql_error());
mysql_select_db("".MYSQL_DB."",$conn) or die(mysql_error());
$sql = "SELECT * FROM test";
$res = mysql_query($sql);
while ($field = mysql_fetch_array($res))
{
$id = $field['id'];
$name = $field['name'];
echo 'ID: ' . $field['id'] . '<br />';
echo 'Name: ' . $field['name'] . '<br /><br />';
}
?>
6. Open up Internet Explorer and type in "http://localhost/mysql_test.php". If the "mysql_test.php" page returns something similiar to:
ID: 1
Name: JohnThe author of the tutorial told me to write and save this in the htdocs.
PHP Syntax (Toggle Plain Text)
<?php # Define MySQL Settings define("MYSQL_HOST", "localhost"); define("MYSQL_USER", "root"); define("MYSQL_PASS", "rashad"); define("MYSQL_DB", "test"); $conn = mysql_connect("".MYSQL_HOST."", "".MYSQL_USER."", "".MYSQL_PASS."") or die(mysql_error()); mysql_select_db("".MYSQL_DB."",$conn) or die(mysql_error()); $sql = "SELECT * FROM test"; $res = mysql_query($sql); while ($field = mysql_fetch_array($res)) { $id = $field['id']; $name = $field['name']; echo 'ID: ' . $field['id'] . '<br />'; echo 'Name: ' . $field['name'] . '<br /><br />'; } ?>
replacing the " password " with my password?
The tutorial link is here : http://www.bicubica.com/apache-php-mysql/index.php
can you use this code and let us know what it returns:
obviously change the password to your password.
php Syntax (Toggle Plain Text)
<?php mysql_connect("localhost","root","password"); $tables = mysql_list_tables("test"); while (list($table) = mysql_fetch_row($tables)) { echo "$table <br />"; } ?>
•
•
Join Date: Jan 2009
Posts: 60
Reputation:
Solved Threads: 4
The problem is that your database is titled test, but the table inside that databse is named "name".
So when you use
You don't need error fallbacks for something as simple as connecting to localhost, so you have alot of unneeded code.
So when you use
$sql = "SELECT * FROM test"; , it's trying to find the table "test" within the database that you connected to at the top of your file. (By the way, that's not a great way to connect to a database via PHP. PHP Syntax (Toggle Plain Text)
//define variables $dbhost = "localhost"; $dbuser = "andrieux"; $dbpass = "pass"; $dbdatabase = "andrieux"; //connect $db = mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($db, $dbdatabase);
You don't need error fallbacks for something as simple as connecting to localhost, so you have alot of unneeded code.
![]() |
Other Threads in the PHP Forum
- Previous Thread: Install WAMP on KUBUNTU
- Next Thread: Installing PHP & Apache 4.0
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array autosuggest beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email emptydisplayvalue error explodefunction file files folder form forms function functions google hack href htaccess html image include insert integration ip java javascript joomla keywords limit link login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search searchbox select server sessions sms soap source space speed sql structure syntax system table tutorial update upload url validation validator variable video web website xml youtube





