|
Posted by MBS on 08/02/05 05:32
paul <paul@not.net> wrote in news:A7adnVBOSN7DRHPfRVn-3Q@speakeasy.net:
> MBS wrote:
> ...
>> // Connect to the database server
>> $dbcnx = @mysql_connect('localhost', 'root', 'mypasswd');
>> if (!$dbcnx) {
>> exit('<p>Unable to connect to the ' .
>> 'database server at this time.</p>');
>> }
>> // Select the jokes database
>> if (!@mysql_select_db('ijdb')) {
>> exit('<p>Unable to locate the joke ' .
>> 'database at this time.</p>');
>> }
> ...
>>
>> $result = @mysql_query('SELECT joketext FROM joke');
>> if (!$result) {
>> exit('<p>Error performing query: ' . mysql_error() . '</p>');
>> }
>> // Display the text of each joke in a paragraph
>> while ($row = mysql_fetch_array($result)) {
>> echo '<p>' . $row['joketext'] . '</p>';
>
>>
>> The problem is that the HTML produced stops after the <body> tag.
>
>
> But you aren't getting any results from those error trapping thingies?
> Try putting print statements in there along the way to debug what's
> happening at each step.
>
> In front of:
>
> if (!$dbcnx) {
>
> put:
>
> print "$dbcnx; //debug
>
> etc.
>
>
>> Also,
>> looking at my MySQL log, I do not see that any connection was made.
>>
>> I also tried mysqli_connect as well. That didn't work, either.
>>
>> Thanks.
>>
>
Sorry. I removed the error-suppressing "@" in the php file on the
server. I forgot to remove them when copying and pasting the code from
the book
I GOT IT TO WORK!!!
The example from the book did not work. But, I found another connection
example and tweaked it. This works:
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error
connecting to mysql');
$dbname = 'ijdb';
mysql_select_db($dbname);
$result = mysql_query('SELECT joketext FROM joke');
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
while ($row = mysql_fetch_array($result)) {
echo '<p>' . $row['joketext'] . '</p>';
}
?>
Thank goodness! I was getting so frustrated. Well, I have a new toy to
play with. Thanks for everyone who took the time to read and/or reply to
my plea for help.
Navigation:
[Reply to this message]
|