Need help with PHP and MySQL: Undefined function...
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Need help with PHP and MySQL: Undefined function...
Hi there!!!
This is the first time that I took PHP and MySQL seriously to learn, but I warn you that I'm still a newbie . Well, some background:
1 - I created a database with MySQL called "mydb". That database has a single table called "workers". (I was using "employees" instead, but I oftenly spell that word wrong, lol ). The table looks like this:
Code:
mysql> show tables;
+----------------+
| Tables_in_mydb |
+----------------+
| workers |
+----------------+
1 row in set (0.00 sec)
Code:
mysql> show columns from workers;
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| id | tinyint(4) | | PRI | NULL | auto_increment |
| first | varchar(20) | YES | | NULL | |
| last | varchar(20) | YES | | NULL | |
| adress | varchar(255) | YES | | NULL | |
| position | varchar(50) | YES | | NULL | |
+----------+--------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
Code:
mysql> select * from workers; +----+-------+---------+-----------------------------+-------------------+
| id | first | last | adress | position |
+----+-------+---------+-----------------------------+-------------------+
| 1 | Bob | Smith | 128 Here St, Citnmame | Marketing Manager |
| 2 | John | Roberts | 45 There St, Townville | Telephonist |
| 3 | Brad | Johnson | 1/34 Nowhere Blvd,
Snowston | Doorman |
+----+-------+---------+-----------------------------+-------------------+
3 rows in set (0.00 sec)
As you can see, everything seems to be working with the database. Now to the PHP code trying to connect to the database:
Whenever I try to open my page, (Apache runs fine and has support for both PHP and MySQL, according to "PHPinfo()") I get this error:
Quote:
Fatal error: Call to undefined function: mysql_connect() in /var/www/html/index.php on line 10
Question 1
That would be the line: $db = mysql_connect("localhost", "root");. I know two problems in there: First, I've to specify my root password right? How? . Second, is Localhost correct? Or should it be my IP Address or something?
Question 2
Now another stupid question.... Where is "mydb" located? I've tried and tried and tried to locate that file, but I could not. This is Mandrake 9.2 if that's of any help.
Thanks a lot for any help, hint or guess in advance .
Last edited by Mega Man X; 06-08-2004 at 06:08 AM.
Oops, almost there . It turns out that I've forgotten to install a package, called "php-mysql". That seems to be the one responsable to connect php code to mysql. Running my page I now get:
Quote:
First Name: Bob
Last Name: Smith
Warning: mysql_result(): address not found in MySQL result index 3 in /var/www/html/index.php on line 16
Address:
Position: Marketing Manager
Ok, I need help with this again. I've recently switched to SuSE 9.1 Professional and, while still trying to learn PHP/MySQL (I will finish it someday, I promise) the very same error as the above has pop up again.
For my surprise, I have php4-mysql package installed. phpinfo() shows "--without-mysql", so that's where the problem is, I guess.
I've figured, it's just a matter to go into /etc/apache2/http.config and uncomment the php4 line. For my astonishment, they've "broke" the hole file, into small parts and used "Include" to add them. No problems there, it looks even more organized. Problem:
I cannot find anywhere on any of the Include files a line to enable PHP4 into Apache2's config. Is there anyone out there using php4/apache2/mysql and preferenclibly with SuSE to guide me in this big dark maze of files and configurations?
PS: I do, have PHP4, Apache and MySQL running. Just cannot connect php to mysql.
I did a big mistake in my post. I mean to find a line in Apache's config to enable mysql, since php does work.
Well, I wanted to remove all the packages and compile Apache, PHP and mysql myself, but I have had bad experiences with that in Slack 9.0, and compiling things in SuSE is not very pleasent .
I fireup YaST and they removed all packages related to apache/php/mysql and installed "Simple webserver with Apache2", a collection of packages including mysql, php and apache2.
hia, im a linux newbie, and im using 9.1 also, and am having the exact same problem, except i dont know how to recomple anything...so what i need is somehow to either do it w/o recompling it, or for someone to give me a detailed step by step on how to recomple php. thank you
Welcome . Try doing what I did, remove all package through YaST and choose the "Simple Web Server with Apache2" in YaST. Then, make sure that both apache and mysql are running:
rcapache2 start rcmysql start
You can just as well start those server under YaST's Runlevel Editor. If the problem persists, post some code here and the exact same error message so we can take a look. I'm very, very bad with PHP, but we never know
ok, so when i try to remove all the packages, some of them wont uninstall, i dont know why, i go into the run level editor, and stop apache and mysql, and then uninstall everything that has either apache, php, or mysql in it, and then restart it, and a few of them are still there, so i dunno what im doin wrong
Also, where did you go to get this simple web server with apache2? i searched for it in the package manager, and in the main menu, im lost on that one.
Is there some code i can put into a file that will make php/apache recognize where my mysql is? that would be the best...
ok thank you
Last edited by andyrewbobb; 09-05-2004 at 04:15 PM.
Ok, so after some searching. i found the simple web server w/apache 2 thing, thanks for that, but i still have the same problem, it wont work w/mysql....i dunno why, phpMyAdmin says mysql is running, and php is running cause i can load the page, but it says that it is --without mysql but in the php.ini file...
Strange... try to initialize the services manually. Open a terminal then:
rcapache2 start rcmysql start
To make sure they are running. If they are, and you are still getting the same error message, try posting everything as I just did: Page's code, PHP and database tables. I had a problem once that was nothing but a typo...
ok heres what i know so far, phpmyadmin is finding mysql, and php, but php is not finding mysql....
the info.php page says this about mysql....
mysql
MySQL Support enabled
Active Persistent Links 0
Active Links 0
Client API version 4.0.18
MYSQL_MODULE_TYPE none
MYSQL_SOCKET /var/lib/mysql/mysql.sock
MYSQL_INCLUDE no value
MYSQL_LIBS no value
Directive Local Value Master Value
mysql.allow_persistent On On
mysql.connect_timeout 60 60
mysql.default_host no value no value
mysql.default_password no value no value
mysql.default_port no value no value
mysql.default_socket no value no value
mysql.default_user no value no value
mysql.max_links Unlimited Unlimited
mysql.max_persistent Unlimited Unlimited
mysql.trace_mode Off Off
and so apparently it can find the socket, but what else it needs i dont know...
mysql folder is /var/lib/mysql/ , and that folder contains...
file:/var/lib/mysql/mysql
file:/var/lib/mysql/test
file:/var/lib/mysql/mysqld.log
file:/var/lib/mysql/mysqld.log-20040913.gz
file:/var/lib/mysql/mysqld.log-20040915.gz
file:/var/lib/mysql/mysqld.pid
file:/var/lib/mysql/mysql.sock
and then the mysql folder contains some more files...
what do i need to do to php to get it to recognize the rest of the files? or where do i need to move the rest of the files to get it to be recognized by php?
or is there some simplier way to do it?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.