newbie: PHP/MYSQL 
Author Message
 newbie: PHP/MYSQL

I'm having problems with php scripts connecting to mysql. When I run a simple script:

<?php
$connection = mysql_connect("host", "user", "password");

if(!$connection) {
  echo "Couldn't make connection!";
  exit;

Quote:
}

I get the following error:

    Fatal error: Call to undefined function: mysql_connect() in /var/www/html/conn.php on line 2

I can connect to the database from the command line.

phpinfo() has "--with-mysql=shared,/usr", so I assume (uh-oh) that is configured correctly (all packages installed from rpm files during RedHat installation).

Is there a manual way I can check that all the right files needed to use MySQL from PHP are present? ANd if not, what would I need to do to get the installation correct?

I have a x86 box running RedHat Linux-9 with Apache-2.0.40, PHP-4.2.2, and MySQL-3.23.54. All these packages were a stock install from the RedHat disribution disks.

Any help would be appreciated (and save my hairline too!)

Thanx,

John  88{Q

--

------------
"Life would be so much easier if we just had the source code."
  - unknown



Tue, 15 Nov 2005 02:58:13 GMT  
 newbie: PHP/MYSQL

Quote:

> I'm having problems with php scripts connecting to mysql. When I run a
> simple script:

> <?php
> $connection = mysql_connect("host", "user", "password");

> if(!$connection) {
>   echo "Couldn't make connection!";
>   exit;
> }

$connection will _not_ be TRUE if the connection succeeds. From the manual:

"Returns a MySQL link identifier on success, or FALSE on failure".

They have an example for connecting, use this instead:

<?php
     $link = mysql_connect("localhost", "mysql_user", "mysql_password")
         or die("Could not connect: " . mysql_error());
     print ("Connected successfully");
     mysql_close($link);
?>

Quote:
> [snipped]

MfG

Geoff.

--
A Formula One [tm](r)(c) Database is available at http://glibs.ssmmdd.co.uk/

Last update: 21st May, 2003 (Next update will be after Monaco GP and
will include a down loadable version).



Tue, 15 Nov 2005 04:03:00 GMT  
 newbie: PHP/MYSQL


Quote:
>> <?php
>> $connection = mysql_connect("host", "user", "password");

>> if(!$connection) {
>>   echo "Couldn't make connection!";
>>   exit;
>> }

>$connection will _not_ be TRUE if the connection succeeds. From the manual:

>"Returns a MySQL link identifier on success, or FALSE on failure".

 Actually, a link identifier in a Boolean context does equate to true. You
could be picky and write "if ($connection === FALSE)" but "!$connection" is
fine.

 See the manual: http://uk.php.net/manual/en/language.types.boolean.php

   "Every other value is considered TRUE (including any resource). "

--

Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)



Tue, 15 Nov 2005 04:18:27 GMT  
 newbie: PHP/MYSQL
The problem is not limited to this particular script (this snippet was
pulled from weberdev.com, to help me troubleshoot the problem).

I've tried installing phpwebsite and phpMyAdmin and they both have problems
connecting. Actually, phpMyAdmin returned an error stating it couldn't load
the MySQL extension and pointed me to this in the documentation:

[1.20] I receive the error "cannot load MySQL extension, please check PHP
Configuration".
To connect to a MySQL server, PHP needs a set of MySQL functions called
"MySQL extension". This extension may be part of the PHP server
(compiled-in), otherwise it needs to be loaded dynamically. Its name is
probably mysql.so or mysql.dll. phpMyAdmin tried to load the extension but
failed.

When I use the snippet you provide, I get the same error are the
"mysql_connect" line.

I should have been more verbose in my description....sorry.

John  88{Q


Quote:

> > I'm having problems with php scripts connecting to mysql. When I run a
> > simple script:

> > <?php
> > $connection = mysql_connect("host", "user", "password");

> > if(!$connection) {
> >   echo "Couldn't make connection!";
> >   exit;
> > }

> $connection will _not_ be TRUE if the connection succeeds. From the
manual:

> "Returns a MySQL link identifier on success, or FALSE on failure".

> They have an example for connecting, use this instead:

> <?php
>      $link = mysql_connect("localhost", "mysql_user", "mysql_password")
>          or die("Could not connect: " . mysql_error());
>      print ("Connected successfully");
>      mysql_close($link);
> ?>

> > [snipped]

> MfG

> Geoff.

> --
> A Formula One [tm](r)(c) Database is available at

http://glibs.ssmmdd.co.uk/

- Show quoted text -

Quote:

> Last update: 21st May, 2003 (Next update will be after Monaco GP and
> will include a down loadable version).



Tue, 15 Nov 2005 04:23:56 GMT  
 newbie: PHP/MYSQL
is it possible that your php has not been compiled with mysql support?

Luke



Tue, 15 Nov 2005 05:05:59 GMT  
 newbie: PHP/MYSQL

Quote:

> is it possible that your php has not been compiled with mysql support?

> Luke

My concern is that the Redhat installation of MySQL and PHP are dispparate, since the RPMs are independent of each other and may make assumptions about each others pathing......just a guess.....

phpinfo() reports that it is....

./configure' '--host=i386-redhat-linux' '--build=i386-redhat-linux' '--target=i386-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/usr/com' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--cache-file=../config.cache' '--with-config-file-path=/etc' '--with-config-file-scan-dir=/etc/php.d' '--enable-force-cgi-redirect' '--disable-debug' '--enable-pic' '--disable-rpath' '--enable-inline-optimization' '--with-bz2' '--with-db3' '--with-curl' '--with-dom=/usr' '--with-exec-dir=/usr/bin' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--with-gd' '--enable-gd-native-ttf' '--with-ttf' '--with-gdbm' '--with-gettext' '--with-ncurses' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--with-png' '--with-pspell' '--with-regex=system' '--with-xml' '--with-expat-dir=/usr' '--with-zlib' '--with-layout=GNU' '--enable-bcmath' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' '--enable-safe-mode' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-discard-path' '--enable-track-vars' '--enable-trans-sid' '--enable-yp' '--enable-wddx' '--without-oci8' '--with-pear=/usr/share/pear' '--with-imap=shared' '--with-imap-ssl' '--with-kerberos=/usr/kerberos' '--with-ldap=shared' '--with-mysql=shared,/usr' '--with-pgsql=shared' '--with-snmp=shared,/usr' '--with-snmp=shared' '--enable-ucd-snmp-hack' '--with-unixODBC=shared' '--enable-memory-limit' '--enable-bcmath' '--enable-shmop' '--enable-versioning' '--enable-calendar' '--enable-dbx' '--enable-dio' '--enable-mcal' '--with-apxs2=/usr/sbin/apxs'



Tue, 15 Nov 2005 05:17:22 GMT  
 newbie: PHP/MYSQL
Im running Suse 7.3, mysql version 3.23.55, and the configure i set down
was just --with-mysql. i didnt use the rpm tho, so i dont know if this
proves anything.

Luke



Tue, 15 Nov 2005 05:56:28 GMT  
 newbie: PHP/MYSQL
The php documentation sez that if you don't specify a path to mysql during
the config stage, php will use it's internal library, which _may_ cause
problems.

I'm just trying to avoid uninstalling mysql AND php and installing from
source, since that may introduce more problems, and take ALOT longer.

Thanks for your input Luke,

John  88{Q


Quote:
> Im running Suse 7.3, mysql version 3.23.55, and the configure i set down
> was just --with-mysql. i didnt use the rpm tho, so i dont know if this
> proves anything.

> Luke



Tue, 15 Nov 2005 06:39:42 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Newbie needs help setting up user MySQL thru PHP

2. Newbie Help with php connection to mysql

3. Newbie Prob with php connection to mysql

4. Newbie: apache+php+python+mysql installation.

5. Newbie Ques: PHP, MySQL & HTML Search Form

6. php mysql sample code php shareware like KB knowledgebase

7. PHP+MySQL vs. PHP+PostgreSQL

8. php + mysql or php + postgresql?

9. Newbie to PHP - Displaying local PHP Files

10. Using remote MySQL server with PHP via HTTP

11. Access Denied error using mySQL through PHP

 

 
Powered by phpBB® Forum Software