trying to figure out how to use a mysql database with PHP. I ran the
following code:
<?php
// defines database connection data
define('DB_HOST', 'localhost');
define('DB_USER', 'ajaxuser');
define('DB_PASSWORD', 'practical');
define('DB_DATABASE', 'ajax');
// connect to the database
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
// the SQL query to execute
$query = 'SELECT user_id, user_name FROM users';
//execute the query
$result = $mysqli->query($query);
// loop through the results
while ($row = $result->fetch_array(MYSQLI_ASSOC))
{
// extract user id and name
$user_id = $row['user_id'];
$user_name = $row['user_name'];
// do somthing with the data (here we output it)
echo 'Name of user #' . $user_id . ' is ' . $user_name . '<br/>';
}
// close the input stream
$result->close();
// close the database connection
$mysqli->close();
?>
I get the following message suggesting that it can't find the
mysqli.dll file:
"Fatal error: Class 'mysqli' not found in
C:\Apache\htdocs\ajax\foundations\mysql\index.php on line 13"
I have the following in php.ini:
extension=php_mysqli.dll
I have php_mysqli.dll in php\ext\. I assume that this is where the
class would be implemented. Is that correct?
Any thoughts what the issue might be?
TIA,
David 12 4166 da******@gmail.com wrote:
trying to figure out how to use a mysql database with PHP. I ran the
following code:
<?php
// defines database connection data
define('DB_HOST', 'localhost');
define('DB_USER', 'ajaxuser');
define('DB_PASSWORD', 'practical');
define('DB_DATABASE', 'ajax');
// connect to the database
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
// the SQL query to execute
$query = 'SELECT user_id, user_name FROM users';
//execute the query
$result = $mysqli->query($query);
// loop through the results
while ($row = $result->fetch_array(MYSQLI_ASSOC))
{
// extract user id and name
$user_id = $row['user_id'];
$user_name = $row['user_name'];
// do somthing with the data (here we output it)
echo 'Name of user #' . $user_id . ' is ' . $user_name . '<br/>';
}
// close the input stream
$result->close();
// close the database connection
$mysqli->close();
?>
I get the following message suggesting that it can't find the
mysqli.dll file:
"Fatal error: Class 'mysqli' not found in
C:\Apache\htdocs\ajax\foundations\mysql\index.php on line 13"
I have the following in php.ini:
extension=php_mysqli.dll
I have php_mysqli.dll in php\ext\. I assume that this is where the
class would be implemented. Is that correct?
Any thoughts what the issue might be?
Did you give readrights to the file for IUSR_<machinename?
If that does not help, you might have hitted incompatible versions of PHP
with mySQL, eg a very old MySQL or PHP version.
Read more about it here: http://nl2.php.net/manual/en/ref.mysqli.php
Regards,
Erwin Moller
>
TIA,
David
Did you give readrights to the file for IUSR_<machinename?
DRS: What is this? How do you do this?
If that does not help, you might have hitted incompatible versions of PHP
with mySQL, eg a very old MySQL or PHP version.
Read more about it here:
DRS: No, they're both very recent versions.
Thanks,
David
I assume that this issue is related to another problem I'm trying to
get some help on. Perhaps it might help identify what's wrong with the
configuration?
Please see http://groups-beta.google.com/group/...daa12?lnk=raot
Thanks!
========================================= da******@gmail.com wrote:
>Did you give readrights to the file for IUSR_<machinename?
DRS: What is this? How do you do this?
rightclick the file -select properties
-select security (or whatever W$ named that on your OS)
-check if IUSR_<machinenameis listed there.
If not, add with readrights.
IUSR_<machinenameshould be replaced by the user on your machine.
So if your server has the name blabla2, this user is called IUSR_blabla2.
It works like this: When IIS gets a request for a certain
file/page/whatever, it tries to open it.
For that it need rights to read the file. Makes sense eh?
So last piece of the puzzle: Who is IIS when it open a file? Answer: IIS
runs as user IUSR_<machinename>
Does that help?
If not come back here.
Regards,
Erwin Moller
>
>If that does not help, you might have hitted incompatible versions of PHP with mySQL, eg a very old MySQL or PHP version. Read more about it here:
DRS: No, they're both very recent versions.
Thanks,
David
$mysqli is a function not a class.
If you want to reuse this function then you need to change the code.
class Mysqli
On Oct 23, 4:18 am, david...@gmail.com wrote:
trying to figure out how to use a mysql database with PHP. I ran the
following code:
<?php
// defines database connection data
define('DB_HOST', 'localhost');
define('DB_USER', 'ajaxuser');
define('DB_PASSWORD', 'practical');
define('DB_DATABASE', 'ajax');
// connect to the database
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
// the SQL query to execute
$query = 'SELECT user_id, user_name FROM users';
//execute the query
$result = $mysqli->query($query);
// loop through the results
while ($row = $result->fetch_array(MYSQLI_ASSOC))
{
// extract user id and name
$user_id = $row['user_id'];
$user_name = $row['user_name'];
// do somthing with the data (here we output it)
echo 'Name of user #' . $user_id . ' is ' . $user_name . '<br/>';
}
// close the input stream
$result->close();
// close the database connection
$mysqli->close();
?>
I get the following message suggesting that it can't find the
mysqli.dll file:
"Fatal error: Class 'mysqli' not found in
C:\Apache\htdocs\ajax\foundations\mysql\index.php on line 13"
I have the following in php.ini:
extension=php_mysqli.dll
I have php_mysqli.dll in php\ext\. I assume that this is where the
class would be implemented. Is that correct?
Any thoughts what the issue might be?
TIA,
David
The issue is that you $mysqli is a function not a class. If you want
to reuse this function then it is worth making it into a class.
The call to $mysqli->XXXXX is a call to a class.
Search for object orientated programing in php, or OOP in PHP. This
will let you make the class that you are after.
On 23 Oct 2006 11:29:32 -0700, "Sy" <si***@outdoorexplorers.comwrote:
>$mysqli is a function not a class. If you want to reuse this function then you need to change the code.
No, the mysqli extension defines a mysqli class for working with MySQL.
--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
If that is a native class to MySQL then ok (I know nothing of MySQL as
that isnt the database i use). However if you are calling a class from
another location then you need to include/require that class in your
code.
i.e.
include "path/to/the/file/that/has/the/class/in/it";
On 23 Oct 2006 11:46:52 -0700, "Sy" <si***@outdoorexplorers.comwrote:
[context restored]
On Mon, 23 Oct 2006 19:42:40 +0100, Andy Hassall <an**@andyh.co.ukwrote:
>No, the mysqli extension defines a mysqli class for working with MySQL.
If that is a native class to MySQL then ok (I know nothing of MySQL as that isnt the database i use). However if you are calling a class from another location then you need to include/require that class in your code.
i.e.
include "path/to/the/file/that/has/the/class/in/it";
No, the mysqli ___extension___ defines a mysqli class for working with MySQL.
--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Sorry to be so dense. See reponses below
Erwin Moller wrote:
rightclick the file -select properties
-select security (or whatever W$ named that on your OS)
-check if IUSR_<machinenameis listed there.
If not, add with readrights.
DRS: The windows properties view doesn't provide a 'add readrights'
feature. By 'machinename', I assume you mean the computer name. There
also is not ability to address computer name in a file's properties
view.
>
IUSR_<machinenameshould be replaced by the user on your machine.
So if your server has the name blabla2, this user is called IUSR_blabla2.
DRS: is the server name the same as the computer name? Are we talking
about the web server (apache) here?
>
It works like this: When IIS gets a request for a certain
file/page/whatever, it tries to open it.
For that it need rights to read the file. Makes sense eh?
So last piece of the puzzle: Who is IIS when it open a file? Answer: IIS
runs as user IUSR_<machinename>
DRS: As I mention above, I'm using Apache. FYI, Apache is serving up
pages just fine. It's the php->mysql interface that's the problem. It's
not clear to me that apache could/should know anything about mysql.
FYI, I've checked out phpMyAdmin's graphical setup facility but I
really don't know what I need to do. I have selected mysqli as the php
extension to use but beyond that, I'm not sure what to do.
Here are a couple of snapshots of the setup utility:
1. Initial screen: http://www.drschwartz.net/personal/...min_setup_1.jpg
2. Configuration overview: http://www.drschwartz.net/personal/...min_setup_2.jpg
Any additional help would be greatly appreciated!
David da******@gmail.com wrote:
Sorry to be so dense. See reponses below
Erwin Moller wrote:
>rightclick the file -select properties -select security (or whatever W$ named that on your OS) -check if IUSR_<machinenameis listed there. If not, add with readrights.
DRS: The windows properties view doesn't provide a 'add readrights'
feature.
No, I didn't claim a button exists with that name...
Which OS are you on?
Does it have a security-tab if you view the properties of the dll?
If you click that securitytab, what do you see?
By 'machinename', I assume you mean the computer name. There
also is not ability to address computer name in a file's properties
view.
Yes, there is. Unless you are running Windows 95 or something.
By the way, if you are using apache, you shouldn't add IUSR_<Machinename>
but find out wich user runs apache first, and give that user readrights.
I don't know by heart since I only run Apache under *nix, and only IIS on
W$.
It should be all in the documentation.
Did you read any documentation?
>> IUSR_<machinenameshould be replaced by the user on your machine. So if your server has the name blabla2, this user is called IUSR_blabla2.
DRS: is the server name the same as the computer name? Are we talking
about the web server (apache) here?
>> It works like this: When IIS gets a request for a certain file/page/whatever, it tries to open it. For that it need rights to read the file. Makes sense eh? So last piece of the puzzle: Who is IIS when it open a file? Answer: IIS runs as user IUSR_<machinename>
DRS: As I mention above, I'm using Apache. FYI, Apache is serving up
pages just fine. It's the php->mysql interface that's the problem. It's
not clear to me that apache could/should know anything about mysql.
FYI, I've checked out phpMyAdmin's graphical setup facility but I
really don't know what I need to do. I have selected mysqli as the php
extension to use but beyond that, I'm not sure what to do.
Here are a couple of snapshots of the setup utility:
1. Initial screen: http://www.drschwartz.net/personal/...min_setup_1.jpg
2. Configuration overview: http://www.drschwartz.net/personal/...min_setup_2.jpg
I couldn't reach those oddly named pages.
Regards,
Erwin Moller
>
Any additional help would be greatly appreciated!
David
No, I didn't claim a button exists with that name...
Which OS are you on?
Does it have a security-tab if you view the properties of the dll?
If you click that securitytab, what do you see?
DRS: No security tab. I'm running Windows XP Home SP2. The dll's
properties view only has 4 tabs: General, Version, Virus Property
(added by my virus program, I'd guess), and Summary. None let me set
any type of readrights for the file.
>
By 'machinename', I assume you mean the computer name. There
also is not ability to address computer name in a file's properties
view.
Yes, there is. Unless you are running Windows 95 or something.
DRS: Not that I can see.
>
By the way, if you are using apache, you shouldn't add IUSR_<Machinename>
but find out wich user runs apache first, and give that user readrights.
DRS: What does 'which user runs apache first' mean? Is that a *nix
issue?
I don't know by heart since I only run Apache under *nix, and only IIS on
W$.
It should be all in the documentation.
Did you read any documentation?
DRS: Not much; I thought I might get a quick answer here.
>
1. Initial screen: http://www.drschwartz.net/personal/...min_setup_1.jpg
2. Configuration overview: http://www.drschwartz.net/personal/...min_setup_2.jpg
I couldn't reach those oddly named pages.
DRS: Sorry about that! The tool collapsed the url. Here's a tinyurl of
the same pages: http://tinyurl.com/ydbd7j http://tinyurl.com/yzcbk2
FYI, I've installed EasyPHP and am able to get data through PHP.
However, I need to use the OO constructs in PHP 5.0. Is it possible to
upgrade EasyPHP to 5.0?
Thanks for your help,
David This discussion thread is closed Replies have been disabled for this discussion. Similar topics
reply
views
Thread by yzzzzz |
last post: by
|
reply
views
Thread by Roy Shaw |
last post: by
|
2 posts
views
Thread by ojorus |
last post: by
|
13 posts
views
Thread by Schmidty |
last post: by
|
2 posts
views
Thread by Curtis |
last post: by
|
21 posts
views
Thread by Daz |
last post: by
|
2 posts
views
Thread by webcm123 |
last post: by
|
2 posts
views
Thread by Michael |
last post: by
| | | | | | | | | | | |