How to use MySQL from PHP ?

How to use MySQL from PHP ?

am 03.01.2008 19:03:22 von YoLed

I have to work with PHP and MySQL but I'm new with this environnement.
So, I've started installing a plateform of mine. So under Windows,
Apache, PHP5 and MySQL.

All sounds right when I write a simple .php page and when I manipulate
a mysql database(s) at command line.

But, when time commes to write something simple using PHP and MySQL, I
get an error : PHP odoesn't seems to recognise a simple instruction like
mysql_connect.

Here is my code :

a db_config.php file containing :
$db_host = "localhost";
$db_user = "php";
$db_password = "f00";
$db_name = "buzzDB";
?>

a temp_con.php file containing :
require($_SERVER["DOCUMENT_ROOT"]."/mysql_test/db_config.php ");
$connection = mysql_connect($db_host, $db_user, $db_password) or die
("error connecting");
echo "connection made";
?>

And when I launch temp_con.php in the framework of the local webserver
(say http://dev-server/mysql_test/temp_con.php), I got this error
message in the web browser :

"Fatal error: Call to undefined function mysql_connect() in Y:\4Apache
\vhosts\dev\htdocs\mysql_test\temp_con.php on line 3"

What's happens ? What should I do ? Is there something missing in the
PHP config to be able to use MySQL commands ?

Re: How to use MySQL from PHP ?

am 03.01.2008 19:09:13 von luiheidsgoeroe

On Thu, 03 Jan 2008 19:03:22 +0100, YoLed wrote:

> I have to work with PHP and MySQL but I'm new with this environnement.
> So, I've started installing a plateform of mine. So under Windows,
> Apache, PHP5 and MySQL.

Look at the installation instructions ar http://www.php.net/mysql
MySQL support is not included by default in PHP5 anymore.
--
Rik Wasmus

Re: How to use MySQL from PHP ?

am 03.01.2008 19:43:20 von YoLed

In article , luiheidsgoeroe@hotmail.com
says...
> On Thu, 03 Jan 2008 19:03:22 +0100, YoLed wrote:
>
> > I have to work with PHP and MySQL but I'm new with this environnement.
> > So, I've started installing a plateform of mine. So under Windows,
> > Apache, PHP5 and MySQL.
>
> Look at the installation instructions ar http://www.php.net/mysql
> MySQL support is not included by default in PHP5 anymore.
>

Oops OK !

So, I've uncommented the line below in php.ini :

extension=php_mysql.dll

Then, I've added "E:\php" to the PATH system variable.
And I've create the variable PHPRC="E:\php" to be sure php.ini be
accessible by PHP.

Now, I will reboot my PC and will be back to tell you if it's now OK...

Re: How to use MySQL from PHP ?

am 03.01.2008 19:50:03 von YoLed

In article ,
invalid@nospam.org says...
> Now, I will reboot my PC and will be back to tell you if it's now OK...
>

It remains the same. I got the same error : "Fatal error: Call to
undefined function mysql_connect() in Y:\4Apache\vhosts\dev\htdocs
\mysql_test\temp_con.php on line 3"

So, do I have forgotten something from the http://fr2.php.net/mysql
instruction about the MySQL activation with PHP5 ?

Re: How to use MySQL from PHP ?

am 03.01.2008 19:58:13 von luiheidsgoeroe

On Thu, 03 Jan 2008 19:43:20 +0100, YoLed wrote:

> In article , luiheidsgoeroe@hotmail.c=
om
> says...
>> On Thu, 03 Jan 2008 19:03:22 +0100, YoLed wrote:=

>>
>> > I have to work with PHP and MySQL but I'm new with this environneme=
nt.
>> > So, I've started installing a plateform of mine. So under Windows,
>> > Apache, PHP5 and MySQL.
>>
>> Look at the installation instructions ar http://www.php.net/mysql
>> MySQL support is not included by default in PHP5 anymore.
>>
>
> Oops OK !
>
> So, I've uncommented the line below in php.ini :
>
> extension=3Dphp_mysql.dll
>
> Then, I've added "E:\php" to the PATH system variable.
> And I've create the variable PHPRC=3D"E:\php" to be sure php.ini be
> accessible by PHP.
>
> Now, I will reboot my PC and will be back to tell you if it's now OK..=
..

Restarting Apache would do.
Reading the _entire_ installation instruction helps though:
'A file named libmysql.dll is included in the Windows PHP distribution a=
nd =

in order for PHP to talk to MySQL this file needs to be available to the=
=

Windows systems PATH.'

Where is your libmysql.dll, and is it available in PATH?

And just to be sure:
'As with enabling any PHP extension (such as php_mysql.dll), the PHP =

directive extension_dir should be set to the directory where the PHP =

extensions are located. See also the Manual Windows Installation =

Instructions. An example extension_dir value for PHP 5 is c:\php\ext'
-- =

Rik Wasmus

Re: How to use MySQL from PHP ?

am 03.01.2008 20:00:04 von luiheidsgoeroe

On Thu, 03 Jan 2008 19:58:13 +0100, Rik Wasmus =

wrote:

> On Thu, 03 Jan 2008 19:43:20 +0100, YoLed wrote:
>
>> In article , luiheidsgoeroe@hotmail.=
com
>> says...
>>> On Thu, 03 Jan 2008 19:03:22 +0100, YoLed wrote=
:
>>>
>>> > I have to work with PHP and MySQL but I'm new with this =

>>> environnement.
>>> > So, I've started installing a plateform of mine. So under Windows,=

>>> > Apache, PHP5 and MySQL.
>>>
>>> Look at the installation instructions ar http://www.php.net/mysql
>>> MySQL support is not included by default in PHP5 anymore.
>>>
>>
>> Oops OK !
>>
>> So, I've uncommented the line below in php.ini :
>>
>> extension=3Dphp_mysql.dll
>>
>> Then, I've added "E:\php" to the PATH system variable.
>> And I've create the variable PHPRC=3D"E:\php" to be sure php.ini be
>> accessible by PHP.
>>
>> Now, I will reboot my PC and will be back to tell you if it's now OK.=
...
>
> Restarting Apache would do.
> Reading the _entire_ installation instruction helps though:
> 'A file named libmysql.dll is included in the Windows PHP distribution=
=

> and in order for PHP to talk to MySQL this file needs to be available =
to =

> the Windows systems PATH.'
>
> Where is your libmysql.dll, and is it available in PATH?
>
> And just to be sure:
> 'As with enabling any PHP extension (such as php_mysql.dll), the PHP =

> directive extension_dir should be set to the directory where the PHP =

> extensions are located. See also the Manual Windows Installation =

> Instructions. An example extension_dir value for PHP 5 is c:\php\ext'


And as an added bonus: examine the output of phpinfo(), is the php.ini =

file you edited the actual php.ini file used?
-- =

Rik Wasmus

Re: How to use MySQL from PHP ?

am 03.01.2008 22:08:53 von Jonas Werres

> So, I've uncommented the line below in php.ini :
>
> extension=php_mysql.dll

Did the idea come to your mind that is not included anymore for some
reason? Use mysqli instead.

Re: How to use MySQL from PHP ?

am 04.01.2008 05:04:38 von Macca

> > extension=php_mysql.dll
>
> Did the idea come to your mind that is not included anymore for some
> reason? Use mysqli instead.

php_mysql.dll is included in the windows download.

Make sure you have the extension_dir in php.ini set correctly. I've
missed that one once or twice.

Then check with phpinfo();

Re: How to use MySQL from PHP ?

am 04.01.2008 09:50:31 von Jonas Werres

> Make sure you have the extension_dir in php.ini set correctly. I've
> missed that one once or twice.

Am I talking to a wall?

There is absolutely no reason for still using mysql_. It lacks some really
nice features of modern MySQL-Versions (although the OP probably wont use
them at least for a long time) and it might NOT be included the download of
the next version.

There is a _reason_ that is not activated.

Re: How to use MySQL from PHP ?

am 04.01.2008 10:53:49 von luiheidsgoeroe

On Fri, 04 Jan 2008 09:50:31 +0100, Jonas Werres wrote:

>> Make sure you have the extension_dir in php.ini set correctly. I've
>> missed that one once or twice.
>
> Am I talking to a wall?
>
> There is absolutely no reason for still using mysql_.

There is. Nice packages, which cost you 80+ hours in development, or at
lest several days to rewrite, might still use it. For new code, I really
can put the analogy to you you shouldn't be using mysqli_* either. I'd use
PDO hands down.
--
Rik Wasmus

Re: How to use MySQL from PHP ?

am 04.01.2008 12:51:09 von YoLed

In article , luiheidsgoeroe@hotmail.com
says...
> Restarting Apache would do.

Done

> Reading the _entire_ installation instruction helps though:
> 'A file named libmysql.dll is included in the Windows PHP distribution and
> in order for PHP to talk to MySQL this file needs to be available to the
> Windows systems PATH.'
> Where is your libmysql.dll, and is it available in PATH?

Done (under E:\php)

> And just to be sure:
> 'As with enabling any PHP extension (such as php_mysql.dll), the PHP
> directive extension_dir should be set to the directory where the PHP
> extensions are located. See also the Manual Windows Installation
> Instructions. An example extension_dir value for PHP 5 is c:\php\ext'
> --
>

Well, the missing part was :
extension_dir = "e:\php\ext"

Thanks

Re: How to use MySQL from PHP ?

am 04.01.2008 14:17:25 von Jerry Stuckle

Jonas Werres wrote:
>> Make sure you have the extension_dir in php.ini set correctly. I've
>> missed that one once or twice.
>
> Am I talking to a wall?
>
> There is absolutely no reason for still using mysql_. It lacks some really
> nice features of modern MySQL-Versions (although the OP probably wont use
> them at least for a long time) and it might NOT be included the download of
> the next version.
>
> There is a _reason_ that is not activated.
>

Sure there is. Sometimes you don't need the newer extensions. And,
being basically wrappers for the C function calls, the mysql_ calls are
faster and require fewer resources. This can be important in busy systems.

I use both, depending on the needs.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: How to use MySQL from PHP ?

am 04.01.2008 15:46:19 von Jonas Werres

> Sure there is. Sometimes you don't need the newer extensions. And,
And you will never need new PHP-versions. Sure. Then it's best to save one
letter.

> being basically wrappers for the C function calls, the mysql_ calls are
> faster and require fewer resources. This can be important in busy
> systems.
Zend does not agree:
"Greater speed. Enhancements in both the extension and in MySQL have made
most operations faster, with certain operations becoming up to 40 times
faster as compared to ext/mysql."
http://devzone.zend.com/node/view/id/686

> I use both, depending on the needs.
What needs?

Re: How to use MySQL from PHP ?

am 04.01.2008 15:47:56 von Jonas Werres

> There is. Nice packages, which cost you 80+ hours in development, or at
> lest several days to rewrite, might still use it. For new code, I really
Ok, in a PHP-group i expect "use" means "code with".
Also replacing mysql_ with mysqli_ should mostly be a thing for sed. Are
there function, where this wont work?

> can put the analogy to you you shouldn't be using mysqli_* either. I'd use
> PDO hands down.
Right, I do, too. But that has nothing to to with mysqli_ being depricated.
I don't want to parent the OT, just prevent him from using legacy stuff by
hook or by crook, because nobody tells him.

Re: How to use MySQL from PHP ?

am 04.01.2008 19:22:12 von Jerry Stuckle

Jonas Werres wrote:
>> Sure there is. Sometimes you don't need the newer extensions. And,
> And you will never need new PHP-versions. Sure. Then it's best to save one
> letter.
>
>> being basically wrappers for the C function calls, the mysql_ calls are
>> faster and require fewer resources. This can be important in busy
>> systems.
> Zend does not agree:
> "Greater speed. Enhancements in both the extension and in MySQL have made
> most operations faster, with certain operations becoming up to 40 times
> faster as compared to ext/mysql."
> http://devzone.zend.com/node/view/id/686
>
>> I use both, depending on the needs.
> What needs?
>
>

Well, that differs with some of my tests. But then they say "Most
operations". They don't talk about the extra overhead (memory and
processing) of the objects themselves.

It depends on the program. Sometimes I find the mysqli_ interface works
better in the program, sometimes the mysql_ interface. It depends on a
lot of factors in the scripts.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: How to use MySQL from PHP ?

am 04.01.2008 19:33:19 von Jonas Werres

> It depends on the program. Sometimes I find the mysqli_ interface works
> better in the program, sometimes the mysql_ interface. It depends on a
> lot of factors in the scripts.

And if mysql_ would exist alongside mysqli_, I would agree. But for
"sometimes, perhaps" you really can't suggest a newbie to use outdated
functions or even risk to write software that perhaps won't run under
the next version yourself.

Re: How to use MySQL from PHP ?

am 05.01.2008 03:32:46 von Jerry Stuckle

Jonas Werres wrote:
>> It depends on the program. Sometimes I find the mysqli_ interface
>> works better in the program, sometimes the mysql_ interface. It
>> depends on a lot of factors in the scripts.
>
> And if mysql_ would exist alongside mysqli_, I would agree. But for
> "sometimes, perhaps" you really can't suggest a newbie to use outdated
> functions or even risk to write software that perhaps won't run under
> the next version yourself.
>

They exist quite well together. All of my systems run both at the same
time.

And I've heard nothing about mysql_ functions going away. In fact, they
are not even listed as deprecated in the PHP 5.x doc.

Do you have other information?

And yes, I do recommend they use when appropriate.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: How to use MySQL from PHP ?

am 05.01.2008 12:09:07 von Tim Streater

In article <1MadnWPh1avicePanZ2dnUVZ_v_inZ2d@comcast.com>,
Jerry Stuckle wrote:

> Jonas Werres wrote:
> >> It depends on the program. Sometimes I find the mysqli_ interface
> >> works better in the program, sometimes the mysql_ interface. It
> >> depends on a lot of factors in the scripts.
> >
> > And if mysql_ would exist alongside mysqli_, I would agree. But for
> > "sometimes, perhaps" you really can't suggest a newbie to use outdated
> > functions or even risk to write software that perhaps won't run under
> > the next version yourself.
> >
>
> They exist quite well together. All of my systems run both at the same
> time.
>
> And I've heard nothing about mysql_ functions going away. In fact, they
> are not even listed as deprecated in the PHP 5.x doc.

Has anyone even heard that they might be?

> Do you have other information?
>
> And yes, I do recommend they use when appropriate.

Prompted by this thread, I had a look at mysqli_ yesterday. Trouble is,
I have some 250 pages all using mysql_. It would be quite a lot of work
to change them, especially since there seems to be no mysqli_result
function. Once the job goes away from being a straight search/replace,
it's gonna get quite long, for me.

If I were starting from scratch, that would be a different matter.

Re: How to use MySQL from PHP ?

am 05.01.2008 15:59:23 von Jonas Werres

> Has anyone even heard that they might be?
They are considered slower that ext/mysqli by Zend, they can do nothing
ext/mysqli can't and they are no longer activated in the default config.
How long do you thing somebody will work on them?

Re: How to use MySQL from PHP ?

am 05.01.2008 16:25:43 von Jerry Stuckle

Jonas Werres wrote:
>> Has anyone even heard that they might be?
> They are considered slower that ext/mysqli by Zend, they can do nothing
> ext/mysqli can't and they are no longer activated in the default config.
> How long do you thing somebody will work on them?
>

YMMV. I've found in many real-life instances they are faster - because
you don't have the overhead of creating the objects.

No, they can't do anything mysqli can't. But so what? That's no
argument. It's just a different way of doing things.

As for not being activated in the default config - neither is the mysqli
extension. In fact, NO mysql extensions are activated.

And as to how long somebody will work on them - for a long, long time.
They haven't even been deprecated yet - and something is deprecated
years before it's dropped. Plus there are probably billions of LOC
which use them.

But you never answered my question. Have you heard they might be
dropped? Give me some references, instead of guesses.

And just because there is something new doesn't mean the old is unusable!

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: How to use MySQL from PHP ?

am 05.01.2008 18:31:56 von Jonas Werres

> YMMV. I've found in many real-life instances they are faster - because
> you don't have the overhead of creating the objects.
It's only importent what the developers think.

> No, they can't do anything mysqli can't. But so what? That's no
> argument. It's just a different way of doing things.
It is, when have to think about paying someone to do the development.

> And as to how long somebody will work on them - for a long, long time.
Even ereg is not marked depricated.

> They haven't even been deprecated yet - and something is deprecated
> years before it's dropped. Plus there are probably billions of LOC
> which use them.
As there are billions of LOCs useing &=? Or var?
Hello, this is PHP!

> But you never answered my question. Have you heard they might be
> dropped? Give me some references, instead of guesses.
Nothing I could cite, no.

> And just because there is something new doesn't mean the old is unusable!
No, not usable. But still stupid to teach it to a newbie.

Re: How to use MySQL from PHP ?

am 06.01.2008 05:18:50 von Jerry Stuckle

Jonas Werres wrote:
>
>> YMMV. I've found in many real-life instances they are faster -
>> because you don't have the overhead of creating the objects.
> It's only importent what the developers think.
>

Wrong. Real life is important.

>> No, they can't do anything mysqli can't. But so what? That's no
>> argument. It's just a different way of doing things.
> It is, when have to think about paying someone to do the development.
>

Yep. They need to pay someone to get the job done in the most
cost-effective way possible. Sometimes that's with mysql_ and sometimes
with mysqli_.

>> And as to how long somebody will work on them - for a long, long time.
> Even ereg is not marked depricated.
>
>> They haven't even been deprecated yet - and something is deprecated
>> years before it's dropped. Plus there are probably billions of LOC
>> which use them.
> As there are billions of LOCs useing &=? Or var?
> Hello, this is PHP!
>

Yep. It is PHP. And mysql_ hasn't been deprecated yet. What is the
shortest amount of time between when you've seen ANY PHP function
deprecated and when it is deprecated?

>> But you never answered my question. Have you heard they might be
>> dropped? Give me some references, instead of guesses.
> Nothing I could cite, no.
>
>> And just because there is something new doesn't mean the old is unusable!
> No, not usable. But still stupid to teach it to a newbie.
>

Only in your opinion. It can be quite usable, and quite useful.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: How to use MySQL from PHP ?

am 08.01.2008 09:59:45 von alex.w474

On Jan 3, 8:03 pm, YoLed wrote:
> I have to work withPHPand MySQL but I'm new with this environnement.
> So, I've started installing a plateform of mine. So under Windows,Apache, PHP5 and MySQL.
>
> All sounds right when I write a simple .phppage and when I manipulate
> a mysql database(s) at command line.
>
> But, when time commes to write something simple usingPHPand MySQL, I
> get an error :PHPodoesn't seems to recognise a simple instruction like
> mysql_connect.
>
> Here is my code :
>
> a db_config.phpfile containing :
> > $db_host = "localhost";
> $db_user = "php";
> $db_password = "f00";
> $db_name = "buzzDB";
> ?>
>
> a temp_con.phpfile containing :
> > require($_SERVER["DOCUMENT_ROOT"]."/mysql_test/db_config.php ");
> $connection = mysql_connect($db_host, $db_user, $db_password) or die
> ("error connecting");
> echo "connection made";
> ?>
>
> And when I launch temp_con.phpin the framework of the local webserver
> (sayhttp://dev-server/mysql_test/temp_con.php), I got this error
> message in the web browser :
>
> "Fatal error: Call to undefined function mysql_connect() in Y:\4Apache
> \vhosts\dev\htdocs\mysql_test\temp_con.phpon line 3"
>
> What's happens ? What should I do ? Is there something missing in thePHPconfig to be able to use MySQL commands ?

Consider http://www.witsuite.com - Apache, PHP, MySQL installer and
configurator, for Windows. It is simple and efficient (installation
demo: http://www.witsuite.com/products/installer/). If you prefer to
install packages manually, you can use the instruction at
http://www.witsuite.com/support/knowledge-base/manual-instal lation/install-php.php.