Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: mysql_connect()

  1. #1
    New Coder
    Join Date
    Jan 2003
    Location
    Rochester, NY
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    mysql_connect()

    I'm new to PHP/MySQL, and hence have a new setup on RH8. I can't seem to get any php scripts to connect to mysql. I have tried a very basic one that just outputs a db .. and an example program that querys a db in html. with an input form.. Is there something else i needed to set up ?


    <html>
    <body>
    <?php

    $db = mysql_connect("localhost", "user", "pass");

    mysql_select_db("fuji",$db);

    $result = mysql_query("SELECT * FROM people",$db);

    printf("Name: %s<br>\n", mysql_result($result,0,"name"));
    printf("Title: %s<br>\n", mysql_result($result,0,"title"));
    printf("Email: %s<br>\n", mysql_result($result,0,"email"));
    printf("AIM: %s<br>\n", mysql_result($result,0,"aim"));
    printf("Cell: %s<br>\n", mysql_result($result,0,"cell"));

    php?>

    </body>
    </html>

    This is the error this generates:

    Fatal error: Call to undefined function: mysql_connect() in /var/www/html/PHP/fuji.php on line 5


    Any ideas?

  • #2
    New Coder
    Join Date
    Jun 2002
    Location
    hamilton,ontario
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <?php

    $db = mysql_connect("localhost", "user", "pass");

    mysql_select_db("fuji");

    $result = mysql_query("SELECT * FROM people");

    php?>


    I _think_ that should do it though I'm not positive.
    whittys.com
    Nomsane?
    That is all

  • #3
    New Coder
    Join Date
    Jan 2003
    Location
    Rochester, NY
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Tried

    I tried that bit of code - it gives me the same error. I'm guessing there is something I have not setup for the php to communicate with the mysql db.

  • #4
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    is that code from webmonkey tutorial ?

    , anyway check to where its all going wrong by using the built in functions...

    PHP Code:
    <?php 
    $db 
    mysql_connect("localhost""user""pass")or die(mysql_error());

    mysql_select_db("fuji")or die(mysql_error());

    $result mysql_query("SELECT * FROM people");
    if(@
    mysql_num_rows($result)){//was any data returned ?//
        
    $r=mysql_fetch_array($result);
        echo 
    "name=".$r['name'];
        echo 
    "<br />email=".$r['email'];
        
    //etc
    }else{
        echo 
    'empty result set!';
    }
    ?>
    you dont need to call die() if you dont want to , just echo mysql_error().
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #5
    New Coder
    Join Date
    Jan 2003
    Location
    Rochester, NY
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    error

    No matter what i do, including the last supplied bit, I get this -

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

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Did you start your sql server before or after your web server? mySQL needs to be loaded first.

  • #7
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Change:

    php?>

    to

    ?>
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #8
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    ok, then your host has disabled mysql support in your PHP configuration/build & without that you are up the spout I am afraid.

    to be sure, run ...
    <?php phpinfo();?>
    (just save that as phpinfo.php)

    and look for mysql in the generated table, but I think thats your problem.


    lol - 3 posts in the same minute - now thats service
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #9
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    doh the version I posted was a bit dodgy ... you dont need the

    '$db = ' bit on the connect line , not that is the problem here,

    Spooks I found out just the other day by accident that

    PHP Code:
    <?php
    echo 'whoot';
    php?>
    does not actually cause an error or even a warning on 4.3.0 , not sure about previous versions though ?
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #10
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Originally posted by firepages

    Spooks I found out just the other day by accident that

    PHP Code:
    <?php
    echo 'whoot';
    php?>
    does not actually cause an error or even a warning on 4.3.0 , not sure about previous versions though ?
    I've never seen PHP script ended like that. At least I don't recall it being in the documentation.

    Since you said it does not cause errors then either it is a bug or they included it in PHP but just really didn't mention it. As the script is parsed it would be read as:

    php
    ?>

    though technically the error would then be that is doesn't recognize the expressoin "php" maybe something like invalid expression on line XX.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #11
    New Coder
    Join Date
    Jan 2003
    Location
    Rochester, NY
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    err..

    Well, i tried stopping and starting the services in the correct order. No changes from that. This is all taking place on a new install of Redhat 8, so there is no host holding me back here. I have tried changing the php?> still nothing.

    I checked the info - PHP version 4.2.2, but there doesn't seem to be anything that says MySQL anywhere on page. MySQL is definitely set up and running, as I am using it on a CL.

    Back to my original though, is there something I need to setup to get MySQL to work with PHP??

    As a side note, unless i ssh into the redhat install, i can't access the MySQL on the redhat from any other machine internally or external.

  • #12
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    "but there doesn't seem to be anything that says MySQL anywhere on page. "

    ok if no host did you compile PHP from source? - if so did you

    ./configure --with-mysql

    if not mysql support wont be included and you will have to recompile with mysql support , you configuration options from your compilation should be shown in the phpinfo() output at the top of the page.

    Spooks , I never saw anywhere that php?> was ok now have I seen it in the documentation either , just found out by accident that it happened to not hurt ?
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #13
    New Coder
    Join Date
    Jan 2003
    Location
    Rochester, NY
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    but..

    But the info page works, and other php scripts are working. Just doesn't seem to think that mysql is there... Also I didn't compile php or mysql as they were both included in the Redhat 8 install. Is there an entry in php.ini that points to mysql?

    Thanks a lot for the ongoing help

    Jason

  • #14
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    in your phpinfo output , the second info block should be called

    "Configure Command" - post the contents of that , if mysql support was not enabled then you wont be able to use MySQL commands without recompiling PHP , I dont think (though wont swear) that you can run dynamically load the mysql libraries.

    To recompile you will need the source rpms for apache mysql and php, so see if they are available on your CD's , recompiling really is much easier than it may sound at first.

    let us know what you have and what you dont have.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #15
    New Coder
    Join Date
    Jan 2003
    Location
    Rochester, NY
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    './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' '--prefix=/usr' '--with-config-file-path=/etc' '--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'


    I am guessing I am going to have to recompile. Any easy instructions?




  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •