|
Posted by yes_its_just_me on 12/18/06 22:43
Hi everyone, I haven't used PHP since version 4 and am trying to use it
for a new project. All I'm trying to do is connect to a MySQL database
and show the contents of that database (as a start). However, nothing
seems to be working. When I execute the script it does nothing, no
error messages, nothing. I know that PHP is working because I've done
the phpinfo(); thing and it works. I also know my database is working
because I can access it from the command line and do whatever I want
with it. So for some reason I'm not able to connect to it from PHP, but
since I'm not getting any errors I have no clue what's wrong. I've
included my code below. This is all set within the body tag. I'm trying
to connect to a database called newsletter_emails and show the results
of a table called newsletter_members. Any help would be appreciated.
Thanks, Josh.
<?php
/* Connect to the MySQL server */
$mysqli = new mysqli('localhost', 'josh', '******',
'newsletter_emails');
/* Check connection */
if(mysqli_connect_errno()) {
printf("Error: Could not connect to MySQL Server. Please try again
later. Errorcode: %s\n", mysqli_connect_error());
exit();
}
/* Send the query to the server */
if($result = mysqli->query('SELECT * FROM newsletter_members')) {
print("Contents:\n");
/* Fetch the results of the query */
while( $row = $result->fetch_assoc() ) {
printf("%s\n", $row['email_addr'], $row['contact_type']);
}
/* Destroy the result set and free the memory used for it */
$result->close();
}
/* Close the connection */
$mysqli->close();
?>
Navigation:
[Reply to this message]
|