set up a php script that has
<?php
php_info();
?>
in it and make sure all the mysql things are set up.
It should be...
I just have a quick one... I am running a server with Apache, PHP, and MySQL. I can't get PHP to connect to MySQL though. I have a few test scripts from a "... for dummies" book, and the scripts that test for PHP alone work just fine. There are scripts to test that MySQL alone is working, and it is fine. However trying to get PHP to connect to MySQL hasn't worked yet. I can connect via command line just fine, but... I was wondering if I need to tell Apache or PHP where on my system the MySQL databases are or...? I have been racking my brains for about two weeks, configuring, reinstalling, etc. and have gotten nowhere. Any help would be great. Thanks.
Asus A8V Deluxe Mobo
AMD Athlon64 X2 4400 -939
2GB Crucial DDR3200 Dual-Channel
ATi AiW 9800 Pro 128DDR
Audigy2 ZS
Sony DRU-810 DVD+RW DL
3 x Maxtor MaxLine SATA 160Gb 16Mb Cache
1 x Maxtor MaxLine SATA 300Gb 16Mb Cache
1 x Maxtor MaxLine SATA 120Gb 16Mb Cache
set up a php script that has
<?php
php_info();
?>
in it and make sure all the mysql things are set up.
It should be...
whatdoyougetwhenyoumultiplysixbynine??
Yeah, I did this after the PHP installation, and it gave me all of the PHP info. I looked at the MySQL section, and it was enabled, and everything looks normal. Here is some of the script that I got from the 'for dummies' book, this script didn't work:
<?php
$user="ron";
$host="localhost";
$password="xxxxx";
/* Section that executes query */
if (@$form == "yes")
{
mysql_connect($host,$user,$password);
mysql_select_db($database);
$query = stripSlashes($query) ;
$result = mysql_query($query);
echo "Database Selected: <b>$database</b><br>
Query: <b>$query</b>
<h3>Results</h3>
<hr>";
if ($result == 0)
echo("<b>Error " . mysql_errno() . ": " . mysql_error() . "</b>");
elseif (@mysql_num_rows($result) == 0)
echo("<b>Query completed. No results returned.</b><br>");
else
{
echo "<table border='1'>
<thead>
<tr>";
for ($i = 0; $i < mysql_num_fields($result); $i++)
{
echo("<th>" . mysql_field_name($result,$i) . "</th>");
}
echo " </tr>
</thead>
<tbody>";
for ($i = 0; $i < mysql_num_rows($result); $i++)
{
echo "<tr>";
$row = mysql_fetch_row($result);
for ($j = 0; $j < mysql_num_fields($result); $j++)
{
echo("<td>" . $row[$j] . "</td>");
}
echo "</tr>";
}
echo "</tbody>
</table>";
}
echo "<hr><br>
<form action=$PHP_SELF method=post>
<input type=hidden name=query value=\"$query\">
<input type=hidden name=database value=$database>
<input type=submit name=\"queryButton\" value=\"New Query\">
<input type=submit name=\"queryButton\" value=\"Edit Query\">
</form>";
unset($form);
exit();
}
/* Section that requests user input of query */
@$query = stripSlashes($query);
if (@$queryButton != "Edit Query")
{
$database = " ";
$query = " ";
}
?>
<form action=<?php echo $PHP_SELF ?>?form=yes method="post">
<table>
<tr>
<td align="right"><b>Type in database name</b></td>
<td>
<input type=text name="database" value=<?php echo $database ?> >
</td>
</tr>
<tr>
<td align="right" valign="top"><b>Type in SQL query</b></td>
<td><textarea name="query" cols="60" rows="10"><?php echo $query ?></textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Submit Query"></td>
</tr>
</table>
</form>
This script does nothing. After I hit the submit button, the fields I filled in blank out, and the window status shows done. I am lost...
Asus A8V Deluxe Mobo
AMD Athlon64 X2 4400 -939
2GB Crucial DDR3200 Dual-Channel
ATi AiW 9800 Pro 128DDR
Audigy2 ZS
Sony DRU-810 DVD+RW DL
3 x Maxtor MaxLine SATA 160Gb 16Mb Cache
1 x Maxtor MaxLine SATA 300Gb 16Mb Cache
1 x Maxtor MaxLine SATA 120Gb 16Mb Cache
you might want to try putting in some debugging.
If you take alook at the commands, they usually return something depending on sucess or failure, so you can run
$test = mysql_connect($host,$user,$password);;
echo $test;
to see if it worked.
Try taking a look around some of the commands you have used and see if they have finished properly.
Also take a look at the php website for some function reference, if you type in php.net/mysql_connect into the address bar it will automatically take you to the correct reference page
Alastair
whatdoyougetwhenyoumultiplysixbynine??
Okay, here is the code that I put in, just to make sure I incorporated it correctly:
<?php
$host="localhost";
$user="ron";
$password="XXXXXXX";
mysql_connect($host,$user,$password);
$test = mysql_connect($host,$user,$password);
echo $test;
?>
When I run it on the server, it printed "Resource id #2". Umm... what on earth?
Asus A8V Deluxe Mobo
AMD Athlon64 X2 4400 -939
2GB Crucial DDR3200 Dual-Channel
ATi AiW 9800 Pro 128DDR
Audigy2 ZS
Sony DRU-810 DVD+RW DL
3 x Maxtor MaxLine SATA 160Gb 16Mb Cache
1 x Maxtor MaxLine SATA 300Gb 16Mb Cache
1 x Maxtor MaxLine SATA 120Gb 16Mb Cache
If you would like to try the script I got from the book, you can do this... Go to 24.10.6.236 and click on mysql-send.php. There are currently two databases, the default mysql, and one called "cams", so you should be able to use that db for a query. The only thing that is bugging me about this whole thing is that I am trying to learn PHP for a project, and it is impossible when even the examples in the book don't work. I mean, I have used a few test scripts (like the ones you will see if you go the site), and everything tells me that the components are working individually, but I have yet to get them to mesh...
Asus A8V Deluxe Mobo
AMD Athlon64 X2 4400 -939
2GB Crucial DDR3200 Dual-Channel
ATi AiW 9800 Pro 128DDR
Audigy2 ZS
Sony DRU-810 DVD+RW DL
3 x Maxtor MaxLine SATA 160Gb 16Mb Cache
1 x Maxtor MaxLine SATA 300Gb 16Mb Cache
1 x Maxtor MaxLine SATA 120Gb 16Mb Cache
Well, that was completely dumb for me to put the address on this board... I can't remember a time when I have had so many hack attempts. Ridiculous. Funny this is, there is nothing to gain by getting into the server, that you can't already get. I really don't see a need to try to get into my /root or / directory unless the person are trying to be malicious. People these days...
Asus A8V Deluxe Mobo
AMD Athlon64 X2 4400 -939
2GB Crucial DDR3200 Dual-Channel
ATi AiW 9800 Pro 128DDR
Audigy2 ZS
Sony DRU-810 DVD+RW DL
3 x Maxtor MaxLine SATA 160Gb 16Mb Cache
1 x Maxtor MaxLine SATA 300Gb 16Mb Cache
1 x Maxtor MaxLine SATA 120Gb 16Mb Cache
Yeah, thats probally wriong..Originally Posted by vwgtiturbo
you could try
@mysql_connect($host,$user,$password) or
die "It failed";
i think is the correct usage
whatdoyougetwhenyoumultiplysixbynine??
Bookmarks