473,414 Members | 1,663 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

PHP MySQL Connect Problem

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();

?>

Dec 18 '06 #1
3 1427
ph***************@yahoo.com schrieb:
When I execute the script it does nothing, no
error messages, nothing.
Hello
Insert error_reporting(E_ALL); on top and try again.
adlerweb
Dec 19 '06 #2

ye*************@yahoo.com schrieb:
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.
You might wish to give PHPDebugger a try, since its
'TADebugger.inc.php' automatically switches to highest error mode and
redirects all error/exception output to PHPDebugger [does not disrupt
your HTML code]:

OS X: http://www.turingart.com/downloads/phpDebugger.zip
Windows: http://www.turingart.com/downloads/phpDebuggerWin.zip

Info: http://www.turingart.com/downloads/p...esentation.pdf

Dec 19 '06 #3
ye*************@yahoo.com wrote:
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.
Could be a number of things - ( eg perhaps selinux is preventing php from
contacting mysql - had that problem on fedora - disable selinux to check )

So would be usefull to know what platform you are on. As the others have
posted some debug info would be helpfull - have a look
in /var/log/httpd/error_log ( on most unix ) that may give some idea of the
problem

Do you have the mysql component of php installed . With php5 the mysql lib
is not bundled ( unlike php4 )

Hope this gives you some pointers
IanR

--
homepage http://narian.org.uk
Dec 20 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jordy | last post by:
Environment: Sun servers running solaris 2.8 Php 4.3.6 Apache 1.3.29 Mysql 4.1.1 phpMyAdmin 2.6.0-alpha1 phpAds 2.0 PhpMyadmin and phpAds don't succeed to connect the MySql database when
0
by: JL | last post by:
Platform: Linux Red Hat RHEL 3 (and red hat 9) Installed MySQL from source. As a matter of fact, installed all LAMPS from source, and the mysql socket file was arranged in a place other than...
0
by: Stefan Hinz | last post by:
Degan, jumping in to try and solve some problems that look pretty obvious to me ... > #options for default service (mysqld2) > (mysqld2) It should be , not (mysqld2).
2
by: Bruce W...1 | last post by:
I've got MySQL running as a service on my Windows 2000 box. And I can work with it using a command window (DOS box). I used the default install of MySQL and here's what status says: mysql>...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
1
by: ikrabbe | last post by:
Hi, I want to set up a mysql server in an embedded process. I managed to start the server in my program as described through mysql_server_init() Now I need a client connection to this...
1
by: jlee | last post by:
I'm pretty much a newbie on mysql, and I need some help. I am running mysql Ver 12.22 Distrib 4.0.24, for portbld-freebsd5.4 (i386) on a server hosting an active website. The site's developer...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
7
by: Ike | last post by:
Let's say I have a MySQL 4.12 database, opened to the internet on 111.111.111.111 allowing all incoming and outgoing ports. I have a username and password setup, which CAN connect to this database,...
2
by: Martin | last post by:
Hi all. I have a fully functional page hosted on my PC that uses PHP and connects to MySQL on my PC to generate it's code. I now have some web hosting available which includes both PHP and...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.